package com.miracle9.game.service;

import com.miracle9.game.bean.Pager;
import com.miracle9.game.dao.*;
import com.miracle9.game.entity.*;
import com.miracle9.game.enums.GameTypeEnums;
import com.miracle9.game.server.message.AmfMessageSend;
import com.miracle9.game.server.message.MessageSend;
import com.miracle9.game.util.*;
import flex.messaging.io.SerializationContext;
import flex.messaging.io.amf.Amf3Output;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.ByteArrayOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("promoterAppService")
public class PromoterAppService extends BaseService {

    private static Logger logger = Logger.getLogger(PromoterAppService.class);
    @Autowired
    private PromoterServiceDao promoterServiceDao;
    @Autowired
    private SystemConfigServiceDao systemConfigServiceDao;
    @Autowired
    private PayApplyServiceDao payApplyServiceDao;
    @Autowired
    private PromoterLogServiceDao promoterLogServiceDao;
    @Autowired
    private AdminService adminService;
    @Autowired
    private UserServiceDao userServiceDao;

    @Autowired
    private UserAwardServiceDao userAwardServiceDao;

    @Autowired
    private ComputerOrderServiceDao computerOrderServiceDao;
    @Autowired
    private PayLogServiceDao payLogServiceDao;
    @Autowired
    private PromoterService promoterService;
    @Autowired
    private Dao dao;
    @Autowired
    private UserService userService;
    @Autowired
    private DeskService deskService;
    @Autowired
    private PromoterServiceDao1 promoterServiceDao1;
    @Autowired
    private PayLogService payLogService;
    @Autowired
    private UserWarningServiceDao userWarningServiceDao;
    @Autowired
    private UserWarningBakServiceDao userWarningBakServiceDao;
    @Autowired
    private LoginRecordDao loginRecordDao;
    @Autowired
    private DeskServiceDao deskServiceDao;
    @Autowired
    private FishDeskServiceDao fishDeskServiceDao;
    @Autowired
    private CardDeskServiceDao cardDeskServiceDao;
    @Autowired
    private BulletFishDeskServiceDao bulletFishDeskServiceDao;
    @Autowired
    private MermaidDeskServiceDao mermaidDeskServiceDao;
    @Autowired
    private WaterDeskServiceDao waterDeskServiceDao;
    @Autowired
    private LiKuiFishDeskDao liKuiFishDeskDao;
    @Autowired
    private GoldenCicadaFishDeskDao goldenCicadaFishDeskDao;
    @Autowired
    private TianGongDeskDao tianGongDeskDao;
    @Autowired
    private BcbmDeskDao bcbmDeskDao;
    @Autowired
    private GoldSharkDeskDao goldSharkdeskDao;

    public void login_getEncrytKey(String pubKey, IoSession session) {
        try {
            Map arg = new HashMap();
            String key = MyUtil.substringLength(16);
            com.miracle9.game.util.GameParameterAssist.bd.put(session, key);
            key = MyUtil.Base64EncodeToStringSettingExponent(key, pubKey);
            int[] gamesArr = com.miracle9.game.util.GameParameterAssist.bu;
            arg.put("games", gamesArr);
            arg.put("key", key);
            arg.put("time", Long.valueOf(System.currentTimeMillis()));
            HashMap map = new HashMap();
            map.put("method", "login_getEncrytKey");
            map.put("args", new Object[]{arg});
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            Amf3Output amf3Output = new Amf3Output(SerializationContext.getSerializationContext());
            amf3Output.setOutputStream(bout);
            amf3Output.writeObject(map);
            amf3Output.flush();
            amf3Output.close();
            byte[] content_out = bout.toByteArray();
            IoBuffer bb = IoBuffer.allocate(content_out.length + 4);
            bb.putInt(content_out.length);
            bb.put(content_out);
            bb.flip();
            session.write(bb);
        } catch (Exception e) {
            logger.error("", e);
        }
    }

    public Map<String, Object> getUserMinus(int userId, String startDate, String endDate, Pager pager, IoSession session) {
        Map map = new HashMap();
        long lastTotalGold = 0L;
        endDate = MyUtil.DateByDayCalendar(endDate, 1);
        User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
        if ((pager.getOrder() == "") && (pager.getOrderBy() == "")) {
            pager.setOrderBy("datetime");
            pager.setOrder("desc");
        }
        pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where username=? and datetime>=? and datetime<=? and type=2",
                pager, new Object[]{user.getUsername(), startDate, endDate});
        List datas = new ArrayList();
        for (Object o : pager.getList()) {
            PayLog payLog = (PayLog) o;
            Map data = new HashMap();
            data.put("datetime", payLog.getDatetime());
            data.put("username", user.getUsername());
            data.put("gold", Integer.valueOf(payLog.getGold()));
            data.put("admin", payLog.getAdmin());
            datas.add(data);
        }
        pager.setList(datas.toArray());
        map.put("pager", pager);

        String hql1 = "select ifnull(sum(gold),0) from pay_log where username=? and datetime>=? and datetime<=? and type=2 ";

        List log = this.userServiceDao.returnList_4(hql1, user.getUsername(), startDate, endDate);
        for (Object o1 : (List) log) {
            lastTotalGold = Long.parseLong(o1.toString());
        }
        map.put("lastTotalGold", Long.valueOf(lastTotalGold));
        return map;
    }
    public Map<String, Object> getUserLoginRec(int userId, String startDate, String endDate, Pager pager, IoSession session) {
        User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
        if (user == null) {
            return null;
        }
        return getLoginRec(userId, 2, user.getUsername(), startDate, endDate, pager);
    }

    public Map<String, Object> getLoginRec(int userId, int userType, String username, String startDate, String endDate, Pager pager) {
        Map map = new HashMap();

        endDate = MyUtil.DateByDayCalendar(endDate, 1);
        if ((pager.getOrder() == "") && (pager.getOrderBy() == "")) {
            pager.setOrderBy("loginDate");
            pager.setOrder("desc");
        }
        pager = this.loginRecordDao.q_CreateSqlsPager("from LoginRecord where userId=? and loginDate>=? and loginDate<? and userType=?", pager, new Object[]{Integer.valueOf(userId), startDate, endDate, Integer.valueOf(userType)});
        List datas = new ArrayList();
        for (Object o : pager.getList()) {
            LoginRecord record = (LoginRecord) o;
            Map data = new HashMap();
            data.put("loginDate", record.getLoginDate());
            data.put("loginIp", record.getLoginIp());
            data.put("userId", Integer.valueOf(userId));
            data.put("username", username);
            data.put("userType", Integer.valueOf(userType));
            datas.add(data);
        }
        pager.setList(datas.toArray());
        map.put("pager", pager);

        return map;
    }
    public Map<String, Object> getUserPlayLog(int userId, String startDate, String endDate, Pager pager, IoSession session) {
        Map map = new HashMap<>();
        endDate = MyUtil.DateByDayCalendar(endDate, 1);
        String hql1 = "from UserTenMinScore where userId=? and startTime>=? and endTime<=?";
        if (pager.getOrderBy() == "") {
            pager = this.userServiceDao.q_CreateSqlsPager(String.valueOf("from UserTenMinScore where userId=? and startTime>=? and endTime<=?") + " order by startTime desc", pager, new Object[]{Integer.valueOf(userId), startDate, endDate});
        } else {
            if (pager.getOrderBy().endsWith("datetime")) {
                pager.setOrderBy("startTime");
            }
            if (pager.getOrderBy().endsWith("userGain")) {
                pager.setOrderBy("yaGold");
            }
            if (pager.getOrderBy().endsWith("userTotalValue")) {
                pager.setOrderBy(" user_total_gold");
            }
            pager = this.userServiceDao.q_CreateSqlsPager("from UserTenMinScore where userId=? and startTime>=? and endTime<=?", pager, new Object[]{Integer.valueOf(userId), startDate, endDate});
        }
        List datas = new ArrayList();
        Object[] list;
        int length = (list = pager.getList()).length;
        for (int i = 0; i < length; i++) {
            Object o = list[i];
            UserTenMinScore utms = (UserTenMinScore) o;
            Map data = new HashMap<>();
            String endTime = utms.getEndTime().substring(utms.getEndTime().indexOf(" ") + 1, utms.getEndTime().length());
            String datetime = String.valueOf(utms.getStartTime()) + "-" + endTime;
            data.put("datetime", datetime);
            data.put("username", utms.getUsername());
            data.put("yaGold", Integer.valueOf(utms.getYaGold()));
            data.put("deGold", Integer.valueOf(utms.getDeGold()));
            data.put("userGain", Integer.valueOf(utms.getYaGold() - utms.getDeGold()));
            data.put("userGold", Integer.valueOf(utms.getUserGold()));
            data.put("userScore", Integer.valueOf(utms.getUserScore()));
            data.put("userTotalValue", Integer.valueOf(utms.getUserTotalGold()));
            datas.add(data);
        }
        pager.setList(datas.toArray());
        map.put("pager", pager);
        long lastYaGold = 0L;
        long lastDeGold = 0L;
        long lastTotalGain = 0L;
        String hql2 = "";
        hql2 = "select ifnull(sum(ya_gold),0) ,ifnull(sum(de_gold),0) from user_ten_min_score where user_id=" + userId + " and start_time>=? and end_time<=? ";
        List<Object[]> log = this.userServiceDao.returnList_3(hql2, startDate, endDate);
        for (Object[] o2 : log) {
            lastYaGold = Long.parseLong(o2[0].toString());
            lastDeGold = Long.parseLong(o2[1].toString());
            lastTotalGain = lastYaGold - lastDeGold;
        }
        map.put("lastTotalPlay", Long.valueOf(lastYaGold));
        map.put("lastTotalGet", Long.valueOf(lastDeGold));
        map.put("lastTotalGain", Long.valueOf(lastTotalGain));
        return map;
    }

    public Map<String, Object> getUserAward(int userId, String startDate, String endDate, Pager pager, IoSession session)
    {
        Map<String, Object> map = new HashMap();
        double lastTotalGold = 0.0D;
        endDate = MyUtil.DateByDayCalendar(endDate, 1);
        if ((pager.getOrder() == "") && (pager.getOrderBy() == ""))
        {
            pager.setOrderBy("datetime");
            pager.setOrder("desc");
        }
        User user = (User)this.userServiceDao.getById(Integer.valueOf(userId));
        pager = this.userAwardServiceDao.q_CreateSqlsPager("from UserAward where userId=? and datetime>=? and datetime<=?", pager, new Object[] {
                Integer.valueOf(userId), startDate, endDate });
        List<Object> datas = new ArrayList();
        for (Object o : pager.getList())
        {
            UserAward ua = (UserAward)o;
            Map<String, Object> data = new HashMap();
            data.put("datetime", ua.getDatetime());
            data.put("username", user.getUsername());
            data.put("gold", Integer.valueOf(ua.getGold()));
            data.put("admin", ua.getAdmin());
            datas.add(data);
        }
        pager.setList(datas.toArray());
        map.put("pager", pager);
        String hql1 = "select ifnull(sum(gold),0) from user_award where user_id=" + userId + " and datetime>=? and datetime<=? ";

        List log = this.userServiceDao.returnList_3(hql1, startDate, endDate);
        for (Object o1 : (List) log) {
            lastTotalGold = Double.parseDouble(o1.toString());
        }
        map.put("lastTotalGold", Double.valueOf(lastTotalGold));
        return map;
    }
    public Map<String, Object> promoterLogin(String userName, String password, int language, IoSession session) {
        try {
            byte[] decodedUsername = MyRsa.getMyRsaInstance().cipherRSA(MyEncode.decode(userName));
            userName = new String(decodedUsername, "UTF-8");
            byte[] decodedPassword = MyRsa.getMyRsaInstance().cipherRSA(MyEncode.decode(password));
            password = new String(decodedPassword, "UTF-8");
            password = new String(decodedPassword, "UTF-8");
            logger.info("username:" + userName + ",password:" + password);
        } catch (Exception e) {
            logger.error("RSA decode username and password wrong:" + e);
            e.printStackTrace();
        }
        Map result = new HashMap();
        result.put("success", Boolean.valueOf(false));
        Promoter promoter = this.promoterServiceDao.getPromoterByUserName(userName);
        if (promoter == null) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(language), "promoterAccountNotExist"));
            return result;
        }
        if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(password))) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(language), "passwordError"));
            return result;
        }
        if (promoter.getState() != 0) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(language), "userAccountDisabled"));
            return result;
        }
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        if ((config != null) && (config.getGameStatus() == 1) && (!userName.equals("yunwei1"))) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(language), "systemMaintenance"));
            return result;
        }
        ClientIpProcess.startMethod().unlockIpSession(session);
        session.setAttribute("username", promoter.getUsername());
        session.setAttribute("id", Integer.valueOf(promoter.getId()));
        session.setAttribute("language", Integer.valueOf(language));
        result.put("success", Boolean.valueOf(true));
        result.put("username", promoter.getUsername());
        result.put("promoterId", Integer.valueOf(promoter.getId()));
        result.put("userPayScale", Integer.valueOf(config.getPayScale()));
        result.put("childPromoterPayScale", Integer.valueOf(promoter.getChildrenPayScale()));
        result.put("goldAuth", promoter.getGoldAuth());
        result.put("fishAuth", promoter.getFishAuth());
        if (promoter.getParentId() > 0) {
            Promoter parent = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoter.getParentId()));
            result.put("promoterPayScale", Integer.valueOf(parent.getChildrenPayScale()));
        } else {
            result.put("promoterPayScale", Integer.valueOf(config.getPromoterPayScale()));
        }
        if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(promoter.getId()))) {
            com.miracle9.game.util.GameParameterAssist.by.put(Integer.valueOf(promoter.getId()), (IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(promoter.getId())));
            notifyAllOperatingLogoffNotice((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(promoter.getId())));
        }
        com.miracle9.game.util.GameParameterAssist.bx.put(Integer.valueOf(promoter.getId()), session);
        String content = "登录管理系统";
        String contentEn = "Login";
        this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
        AmfMessageSend.processStorageInfo(new com.miracle9.game.server.message.StorageMethodEntity(session, "promoterLogin", new Object[]{result}));
        afterLogin(session);
        LoginRecord loginRecord = new LoginRecord();
        loginRecord.setLoginDate(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
        loginRecord.setUserId(promoter.getId());
        loginRecord.setLoginIp((String) session.getAttribute("ip"));
        loginRecord.setUserType(1);
        this.loginRecordDao.addLoginRecord(loginRecord);
        return result;
    }

    public Map<String, Object> promoterLogout(int promoterId, IoSession session) {
        Integer id = Integer.valueOf(session.getAttribute("id").toString());
        Map result;
        if (promoterId != id.intValue()) {
            result = resultFormat(false, "");
        } else {
            if (com.miracle9.game.util.GameParameterAssist.by.containsKey(id)) {
                IoSession s = (IoSession) com.miracle9.game.util.GameParameterAssist.by.remove(id);
                s.removeAttribute("id");
                s.removeAttribute("username");
                s.removeAttribute("language");
            } else if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(id)) {
                IoSession s = (IoSession) com.miracle9.game.util.GameParameterAssist.bx.remove(id);
                s.removeAttribute("id");
                s.removeAttribute("username");
                s.removeAttribute("language");
            }
            result = resultFormat(true, "");
            String content = "退出管理系统";
            String contentEn = "Log out";
            this.promoterLogServiceDao.save_3(promoterId, content, contentEn);
        }
        return result;
    }

    public Map<String, Object> getPromoterInfo(int promoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "notFoundPromoter"));
        } else {
            result = resultFormat(true, "");
            result.put("username", promoter.getUsername());
            result.put("gold", Integer.valueOf(promoter.getGold()));
            result.put("parentName", promoter.getParentName());
            int payScale = 100;
            if ((promoter.getParentId() > 0) && (promoter.getParentName() != null) && (!"".equals(promoter.getParentName()))) {
                Promoter parent = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoter.getParentId()));
                payScale = parent.getChildrenPayScale();
            } else {
                SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
                payScale = config.getPromoterPayScale();
            }
            result.put("goldScale", Double.valueOf(MyUtil.doubleDivideCalculation(payScale, 100.0D)));
            result.put("childrenPromoterNum", Integer.valueOf(promoter.getChildrenPromoterNum()));
            result.put("childrenUserNum", Integer.valueOf(promoter.getChildrenUserNum()));
        }
        return result;
    }

    public Map<String, Object> promoterPay(int promoterId, int money, String remark, IoSession session) {
        Map result = new HashMap();
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        if (config.getExpiry() == -1) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "cannotApply"));
            return result;
        }
        if (money <= 0) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "paramError"));
            return result;
        }
        synchronized (PayApplyService.expiryLock) {
            Promoter promoter = (Promoter) this.promoterServiceDao.q_CreateSqlFilter("from Promoter where id=?", new Object[]{Integer.valueOf(promoterId)});
            if (promoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "notFoundPromoter"));
            } else {
                if (promoter.getState() != 0) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "userAccountDisabled"));
                    return result;
                }
                if (promoter.getPayMoney() > 0) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "doNotRepeatApply"));
                } else {
                    if (remark == null) {
                        remark = "";
                    }
                    if (remark.length() > 200) {
                        remark = remark.substring(0, 200);
                    }
                    this.promoterServiceDao.updatePayMoney(promoterId, money);
                    PayApply payApply = new PayApply(MyUtil.c(), money, promoterId, remark, PayApply.PayApplyState.PENDING, System.currentTimeMillis() + config.getExpiry() * 60000, 1, 0, false);
                    this.payApplyServiceDao.save(payApply);
                    this.payApplyServiceDao.getAllPayApply().add(payApply);
                    result = resultFormat(true, MyUtil.getSessionAttribute(session, "promoterPayApply"));
                    if (promoter.getParentId() == 0) {
                        Map countMap = this.promoterService.getPromoterPayCount();
                        for (IoSession s : com.miracle9.game.util.GameParameterAssist.be.values()) {
                            AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(s, "promoterPayCount", new Object[]{countMap}));
                        }
                    } else if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(promoter.getParentId()))) {
                        promoterAppPayCount((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(promoter.getParentId())), promoter.getParentId());
                    }
                    String content = "向上级发送了金额为" + money + "元的充值申请";
                    String contentEn = "Sent a recharge application of " + money + " yuan to superrior";
                    this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                }
            }
        }
        return result;
    }

    public Map<String, Object> promoterExpiry(int promoterId, int number, String remark, String password, IoSession session) {
        Map result = new HashMap();
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        if (config.getExpiry() == -1) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "cannotApply"));
            return result;
        }
        if ((promoterId < 0) || (number < 0)) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "paramError"));
            return result;
        }
        synchronized (PayApplyService.expiryLock) {
            Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
            if (promoter.getState() != 0) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "userAccountDisabled"));
                return result;
            }
            if ((promoter == null) || (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(password)))) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
            } else if (promoter.getGold() < number) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
            } else if (promoter.getExpiryNum() > 0) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "doNotRepeatApply"));
            } else {
                if (remark == null) {
                    remark = "";
                }
                if (remark.length() > 200) {
                    remark = remark.substring(0, 200);
                }
                this.promoterServiceDao.updateGoldById(promoterId, number);
                this.promoterServiceDao.updateExpiryNum(promoterId, number);
                PayApply payApply = new PayApply(MyUtil.dateFormatYMD_HMS_Sting(new Date()), number, promoterId, remark, PayApply.PayApplyState.PENDING, System.currentTimeMillis() + config.getExpiry() * 60000, 1, 1, false);
                this.payApplyServiceDao.save(payApply);
                this.payApplyServiceDao.getAllPayApply().add(payApply);
                result = resultFormat(true, "");
                if (promoter.getParentId() == 0) {
                    Map countMap = this.promoterService.getPromoterPayCount();
                    for (IoSession s : com.miracle9.game.util.GameParameterAssist.be.values()) {
                        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(s, "promoterPayCount", new Object[]{countMap}));
                    }
                } else if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(promoter.getParentId()))) {
                    promoterAppPayCount((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(promoter.getParentId())), promoter.getParentId());
                }
                String content = "向上级发送了额度为" + number + "的兑奖申请";
                String contentEn = "Sent a exchange application of " + number + " coins to superior";
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
            }
        }
        return result;
    }

    public double getUserPayScale(IoSession session) {
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        double d = MyUtil.doubleDivideCalculation(config.getPayScale(), 100.0D);
        return d;
    }

    public double getChildPromoterPayScale(int promoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            return 0.0D;
        }
        return MyUtil.doubleDivideCalculation(promoter.getChildrenPayScale(), 100.0D);
    }

    public Map<String, Object> updateChildPromoterPayScale(int promoterId, String rate, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "notFoundPromoter"));
        } else {
            int childPromoterPayScale = (int) MyUtil.doubleMultiplyCalculation(Double.valueOf(rate).doubleValue(), 100.0D);
            if (this.promoterServiceDao.updateChildrenPayScaleId(promoterId, childPromoterPayScale)) {
                result = resultFormat(true, "");
                result.put("scale", Integer.valueOf(childPromoterPayScale));
                String content = "设置直属推广员充值比例为" + rate;
                String contentEn = "Change the recharge ratio of all members to " + rate;
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                List<Promoter> promoters = this.promoterServiceDao.getPromotersByPromoterId(promoterId);
                for (Promoter p : promoters) {
                    IoSession s = (IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(p.getId()));
                    if (s != null) {
                        syncPromoterPayScale(childPromoterPayScale, s);
                    }
                }
            } else {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "setError"));
            }
        }
        return result;
    }

    public int getChildUserOver(int promoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            return 0;
        }
        return promoter.getChildrenUserOver();
    }

    public Map<String, Object> setChildUserOver(int promoterId, int userOver, IoSession session) {
        Map result = new HashMap();
        if (this.promoterServiceDao.updateChildrenUserOverById(promoterId, userOver)) {
            String content = "设置直属会员爆机值为" + userOver;
            String contentEn = "Change the max value of coins of direct member to " + userOver;
            this.promoterLogServiceDao.save_3(promoterId, content, contentEn);
            result = resultFormat(true, "");
            if (userOver == -1) {
                List<User> users = this.userServiceDao.q_CreateSqlList("from User where promoterId=? and overflow=1 and status in (0,1)", new Object[]{Integer.valueOf(promoterId)});
                if (!users.isEmpty()) {
                    this.userServiceDao.q_Update("update User set overflow=0 where promoterId=? and overflow=1 and status in (0,1)", new Object[]{Integer.valueOf(promoterId)});
                    for (User u : users) {
                        if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(u.getId()))) {
                            MessageSend.q.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(u.getId())), "unOverflow", new Object[0]));
                        }
                    }
                }
            } else {
                SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
                List<User> users = this.userServiceDao.q_CreateSqlList("from User where promoterId=? and status in (0,1)", new Object[]{Integer.valueOf(promoterId)});
                for (User u : users) {
                    if (u.getGameGold() * config.getPayScale() >= userOver * 100) {
                        if (u.getOverflow() == 0) {
                            this.userServiceDao.updateOverflow(u.getId(), 1);
                            UserService.pubOverflowNotice(u.getId());
                        }
                    } else if (u.getOverflow() == 1) {
                        this.userServiceDao.updateOverflow(u.getId(), 0);
                        if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(u.getId()))) {
                            MessageSend.q.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(u.getId())), "unOverflow", new Object[0]));
                        }
                    }
                }
            }
        } else {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "setError"));
        }
        return result;
    }

    public Map<String, Object> resetPromoterPwd(int promoterId, String oldPwd, String newPwd, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(oldPwd))) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "oldPasswordError"));
        } else if (this.promoterServiceDao.updatePasswordById(promoterId, MyUtil.strPwdMd5Hex(newPwd))) {
            result = resultFormat(true, "");
            String content = "修改了密码";
            String contentEn = "The password has been changed";
            this.promoterLogServiceDao.save_3(promoterId, content, contentEn);
        } else {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "setError"));
        }
        return result;
    }

    public Pager queryPromoterPayLog(int promoterId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,money desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("money desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where userId=? and type=0 and userType=1 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), date + "%"});
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public double getPromoterPaySum(int promoterId, String date, IoSession session) {
        return this.promoterServiceDao.getSumMoneyByUidAndDate(promoterId, date);
    }

    public Pager queryPromoterExpiryLog(int promoterId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,money desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("money desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where userId=? and type=1 and userType=1 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), date + "%"});
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public double getPromoterExpirySum(int promoterId, String date, IoSession session) {
        return this.promoterServiceDao.getSumMoneyByUidAndInterval(promoterId, date);
    }

    public Map<String, Object> enterExpiryPwd(int promoterId, String pwd, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        IoSession waitSession = null;
        Iterator localIterator = com.miracle9.game.util.GameParameterAssist.bz.entrySet().iterator();
        while (localIterator.hasNext()) {
            Map.Entry entry = (Map.Entry) localIterator.next();
            if (((Map) entry.getValue()).containsKey(Integer.valueOf(promoterId))) {
                waitSession = (IoSession) entry.getKey();
            }
        }
        Map result;
        if (waitSession != null) {
            Map manage = new HashMap();
            if ((promoter == null) || (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd)))) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
                manage.put("success", Boolean.valueOf(false));
                manage.put("message", MyUtil.getSessionAttribute(waitSession, "extensionInputPwdError"));
                manage.put("type", Integer.valueOf(3));
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(waitSession, "getGameInput", new Object[]{manage}));
            } else {
                result = resultFormat(true, "");
                if (promoter.getParentId() == 0) {
                    manage.put("success", Boolean.valueOf(true));
                    manage.put("message", "");
                    manage.put("type", Integer.valueOf(3));
                    AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(waitSession, "getGameInput", new Object[]{manage}));
                } else {
                    int gold = ((Integer) com.miracle9.game.util.GameParameterAssist.bB.get(Integer.valueOf(promoterId))).intValue();
                    Promoter parent = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoter.getParentId()));
                    boolean b = this.promoterServiceDao.updateGoldById(promoterId, gold);
                    if (b) {
                        this.promoterServiceDao.addGold(promoter.getParentId(), gold);
                    } else {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
                        return result;
                    }
                    double money = MyUtil.goldExchange(gold, parent.getChildrenPayScale());
                    manage.put("success", Boolean.valueOf(true));
                    manage.put("message", MyUtil.format(MyUtil.getSessionAttribute(waitSession, "expiryForPromoterTip"), new Object[]{promoter.getUsername(), Integer.valueOf(gold), Double.valueOf(money)}));
                    manage.put("type", Integer.valueOf(3));
                    AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(waitSession, "getGameInput", new Object[]{manage}));
                    this.payLogServiceDao.saveReturnByType_1UserType_1(promoterId, promoter.getUsername(), gold, money, parent.getUsername(), 0, "", parent.getId(), promoter.getGold() + promoter.getExpiryNum());
                    String content = "对直属推广员" + promoter.getUsername() + "进行了\"兑奖\"操作，金额为" + money + "元";
                    String contentEn = "Exchange " + gold + " coins for the direct extension which ID is " + promoter.getUsername();
                    this.promoterLogServiceDao.save_3(promoter.getParentId(), content, contentEn);
                    if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(promoterId))) {
                        notifyAllOperating(session, MyUtil.format(MyUtil.getSessionAttribute(session, "promoterExpiryActive"), new Object[]{Integer.valueOf(gold)}));
                    }
                }
            }
            com.miracle9.game.util.GameParameterAssist.bz.remove(waitSession);
            com.miracle9.game.util.GameParameterAssist.bB.remove(Integer.valueOf(promoterId));
        } else {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "superiorCancelledExchange"));
        }
        return result;
    }

    public Map<String, Object> cancelExpiryPwd(int promoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Iterator localIterator = com.miracle9.game.util.GameParameterAssist.bz.entrySet().iterator();
            while (localIterator.hasNext()) {
                Map.Entry entry = (Map.Entry) localIterator.next();
                if (((Map) entry.getValue()).containsKey(Integer.valueOf(promoterId))) {
                    Map manage = new HashMap();
                    manage.put("success", Boolean.valueOf(false));
                    manage.put("message", MyUtil.getSessionAttribute(session, "extensionCancelledExchange"));
                    manage.put("type", Integer.valueOf(3));
                    AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) entry.getKey(), "getGameInput", new Object[]{manage}));
                    com.miracle9.game.util.GameParameterAssist.bz.remove(entry.getKey());
                    com.miracle9.game.util.GameParameterAssist.bB.remove(Integer.valueOf(promoterId));
                    break;
                }
            }
            result = resultFormat(true, "");
        }
        return result;
    }

    public void syncUserPayScale(int payScale, IoSession ioSession) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "syncUserPayScale", new Object[]{Integer.valueOf(payScale)}));
    }

    public static void syncPromoterPayScale(int payScale, IoSession ioSession) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "syncPromoterPayScale", new Object[]{Integer.valueOf(payScale)}));
    }

    public void heart(IoSession session) {
        com.miracle9.game.util.GameParameterAssist.bA.put(session, Long.valueOf(System.currentTimeMillis()));
        MessageSend.q.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "heart", new Object[0]));
    }

    public Pager queryChildPromoter(int promoterId, String searchWord, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("payMoney desc,expiryNum desc,username asc,gold desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("payMoney desc");
            orderby.add("expiryNum desc");
            orderby.add("username asc");
            orderby.add("gold desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        if ((searchWord != null) && (!"".equals(searchWord.trim()))) {
            pager = this.promoterServiceDao.q_CreateSqlsPager("from Promoter where parentId=? and username like ?", pager, new Object[]{Integer.valueOf(promoterId), "%" + searchWord + "%"});
            String content = "通过\"" + searchWord + "\"进行了直属推广员搜索操作";
            String contentEn = "Searched by direct extension and " + searchWord;
            this.promoterLogServiceDao.save_3(promoterId, content, contentEn);
        } else {
            pager = this.promoterServiceDao.q_CreateSqlsPager("from Promoter where parentId=?", pager, new Object[]{Integer.valueOf(promoterId)});
        }
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public int getChildPromoterGold(int promoterId, String searchWord, IoSession session) {
        return this.promoterServiceDao.ifGetPromoterParameter2(promoterId, searchWord);
    }

    public Map<String, Object> getChildPromoterInfo(int promoterId, int childPromoterId, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter != null) {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter != null) {
                if (childPromoter.getParentId() == promoterId) {
                    result.put("gold", Integer.valueOf(childPromoter.getGold()));
                    result.put("promoterCount", Integer.valueOf(childPromoter.getChildrenPromoterNum()));
                    result.put("userCount", Integer.valueOf(childPromoter.getChildrenUserNum()));
                    result.put("payMoney", Integer.valueOf(childPromoter.getPayMoney()));
                    result.put("expiryNum", Integer.valueOf(childPromoter.getExpiryNum()));
                    result.put("state", childPromoter.getState() == 0 ? MyUtil.getSessionAttribute(session, "normal") : MyUtil.getSessionAttribute(session, "disabled"));
                    result.put("datetime", childPromoter.getCreateTime());
                    result.put("remark", childPromoter.getRemark());
                }
            }
        }
        return result;
    }

    public int getChildPromoterToDoCount(int promoterId, IoSession session) {
        return this.promoterServiceDao.nestingGeSumCntByParentId(promoterId);
    }

    public int getChildUserToDoCount(int promoterId, IoSession session) {
        return this.promoterServiceDao.nestingsGeSumCntByParentId(promoterId);
    }

    public Map<String, Object> addPromoter(int parentId, String userName, String registCode, String remark, IoSession session) {
        Map result = new HashMap();
        boolean enabled = this.adminService.checkPromoterCode(registCode);
        if (!enabled) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "registCodeError"));
            return result;
        }
        int count = this.promoterServiceDao.q_CreateSqlInt("select count(*) from Promoter where registCode = ?", new Object[]{registCode});
        if (count > 0) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getSessionAttribute(session, "registCodeUsed"));
            return result;
        }
        int promoterCount = this.promoterServiceDao1.q_CreateSqlInt("select count(*) from Promoter", new Object[0]);
        if (promoterCount >= 100) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "promoterLimit"));
            return result;
        }
        Promoter promoter = this.promoterServiceDao.getPromoterByUserName(userName);
        if (promoter != null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "promoterUserExist"));
        } else {
            Promoter parent = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(parentId));
            if (parent == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                promoter = new Promoter();
                promoter.setUsername(userName);
                promoter.setPassword(MyUtil.strPwdMd5Hex("888888"));
                promoter.setParentId(parentId);
                promoter.setParentName(parent.getUsername());
                promoter.setLevel(parent.getLevel() + 1);
                promoter.setGold(0);
                promoter.setState(0);
                SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
                if (config.getPayScale() > parent.getChildrenPayScale() + 5) {
                    promoter.setChildrenPayScale(parent.getChildrenPayScale() + 5);
                } else {
                    promoter.setChildrenPayScale(config.getPayScale());
                }
                promoter.setExpiryNum(0);
                promoter.setPayMoney(0);
                promoter.setRemark(remark);
                promoter.setChildrenUserNum(0);
                promoter.setChildrenPromoterNum(0);
                promoter.setRegistCode(registCode);
                promoter.setCreateTime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
                this.promoterServiceDao.save(promoter);
                this.promoterServiceDao.updateChildrenPromoterNumById(parentId);
                String content = "新增直属推广员" + userName;
                String contentEn = "Add a new extension which ID is " + userName;
                this.promoterLogServiceDao.save_3(parentId, content, contentEn);
                result = resultFormat(true, "");
            }
        }
        return result;
    }

    public Map<String, Object> approveChildPromoterExpiry(int promoterId, int childPromoterId, int gold, String pwd, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd))) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
            } else {
                Promoter childPromoter =
                        (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
                if (childPromoter == null) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
                } else {
                    if (childPromoter.getState() != 0) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "extensionAccountDisabled"));
                        return result;
                    }
                    synchronized (PayApplyService.expiryLock) {
                        PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(childPromoterId, 1);
                        if (payApply == null) {
                            result = resultFormat(false, MyUtil.getSessionAttribute(session, "expiryTimeout"));
                        } else {
                            gold = payApply.getAmmount();
                            this.promoterServiceDao.updateExpiryNum(childPromoterId, 0);
                            this.promoterServiceDao.addGold(promoterId, gold);
                            payApply.setDatetime(MyUtil.c());
                            payApply.setState(PayApply.PayApplyState.HANDLED);
                            double money = MyUtil.goldExchange(gold, promoter.getChildrenPayScale());
                            if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                                notifyAllOperatingMessage((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)), MyUtil.format(MyUtil.getSessionAttribute(session, "promoterExpiryApprovedTip"), new Object[]{MyUtil.c(), Integer.valueOf(gold)}));
                                payApply.setNotice(true);
                            }
                            this.payApplyServiceDao.update(payApply);
                            this.payLogServiceDao.saveReturnByType_1UserType_1(childPromoterId, childPromoter.getUsername(), gold, money, promoter.getUsername(), 1, "", promoterId, childPromoter.getGold() + childPromoter.getExpiryNum());
                            String content = "对直属推广员" + childPromoter.getUsername() + "进行了兑奖操作，金额为" + money + "元";
                            String contentEn = "Exchange " + gold + " coins for the direct extension which ID is " + childPromoter.getUsername();
                            this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                            promoterAppPayCount(session, promoterId);
                            result = resultFormat(true, MyUtil.format(MyUtil.getSessionAttribute(session, "expiryForPromoterTip"), new Object[]{childPromoter.getUsername(), Integer.valueOf(gold), Double.valueOf(money)}));
                            List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                            for (PayApply ul : logs) {
                                if (ul.getId() == payApply.getId()) {
                                    logs.remove(ul);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> denyChildPromoterExpiry(int promoterId, int childPromoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                synchronized (PayApplyService.expiryLock) {
                    PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(childPromoterId, 1);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "payTimeout"));
                    } else {
                        this.promoterServiceDao.updateExpiryNum(childPromoterId, 0);
                        result = resultFormat(true, "");
                        this.promoterServiceDao.addGold(childPromoterId, payApply.getAmmount());
                        payApply.setState(PayApply.PayApplyState.WAIVE);
                        if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                            payApply.setNotice(true);
                            notifyAllOperatingMessage((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)), MyUtil.getSessionAttribute(session, "promoterExpiryDeniedTip"));
                        }
                        this.payApplyServiceDao.update(payApply);
                        promoterAppPayCount(session, promoterId);
                        List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                        for (PayApply ul : logs) {
                            if (ul.getId() == payApply.getId()) {
                                logs.remove(ul);
                                break;
                            }
                        }
                    }
                }
            }
        }
        return result;
    }

    public Pager queryChildUser(int promoterId, String searchWord, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("payMoney desc,expiryNum desc, username asc, gameGold desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("payMoney desc");
            orderby.add("expiryNum desc");
            orderby.add("username asc");
            orderby.add("gameGold desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        if ((searchWord == null) || ("".equals(searchWord))) {
            pager = this.userServiceDao.q_CreateSqlsPager("from User where promoterId=? and status in (0,1,2,3)", pager, new Object[]{Integer.valueOf(promoterId)});
        } else {
            pager = this.userServiceDao.q_CreateSqlsPager("from User where promoterId=? and status in (0,1,2,3) and username like ?", pager, new Object[]{Integer.valueOf(promoterId), "%" + searchWord + "%"});
        }
        for (Object o : pager.getList()) {
            User user = (User) o;
            Integer deskId = getUserCurrentDeskId(user);
            if (deskId != null) {
                user.setCurrentDesk(deskId);
                if (GameTypeEnums.GT_0.getType() == user.getLastGame()) {
                    Desk desk = deskServiceDao.getDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_0.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_1.getType() == user.getLastGame()) {
                    FishDesk desk = fishDeskServiceDao.getFishDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_1.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_2.getType() == user.getLastGame()) {
                    CardDesk desk = (CardDesk) cardDeskServiceDao.getById(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_2.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_3.getType() == user.getLastGame()) {
                    BulletFishDesk desk = bulletFishDeskServiceDao.getBulletDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_3.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_4.getType() == user.getLastGame()) {
                    MermaidDesk desk = mermaidDeskServiceDao.getMermaidDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_4.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_5.getType() == user.getLastGame()) {
                } else if (GameTypeEnums.GT_6.getType() == user.getLastGame()) {
                } else if (GameTypeEnums.GT_7.getType() == user.getLastGame()) {
                    WaterDesk desk = waterDeskServiceDao.getWaterDeskByDeskId(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_7.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_9.getType() == user.getLastGame()) {
                } else if (GameTypeEnums.GT_11.getType() == user.getLastGame()) {
                } else if (GameTypeEnums.GT_20.getType() == user.getLastGame()) {
                    LiKuiFishDesk desk = liKuiFishDeskDao.getLiKuiFishDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_20.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_37.getType() == user.getLastGame()) {
                    GoldenCicadaFishDesk desk = goldenCicadaFishDeskDao.getGoldenCicadaFishDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_37.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_42.getType() == user.getLastGame()) {
                    GoldSharkDesk desk = goldSharkdeskDao.getDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_42.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_52.getType() == user.getLastGame()) {
                    BcbmDesk desk = bcbmDeskDao.getBcbmDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_52.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                } else if (GameTypeEnums.GT_92.getType() == user.getLastGame()) {
                    TianGongDesk desk = tianGongDeskDao.getTianGongDesk(deskId);
                    if (desk != null) {
                        user.setCurrentDeskName(GameTypeEnums.GT_92.getName() + "-" + desk.getName());
                        user.setCurrentGold(user.getGameScore() / desk.getExchange());
                    }
                }
            }
        }
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    private Integer getUserCurrentDeskId(User user) {
        if (GameTypeEnums.GT_0.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.bm.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_1.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.bn.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_2.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.bo.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_3.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.bp.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_4.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.bq.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_5.getType() == user.getLastGame()) {
            return null;
        } else if (GameTypeEnums.GT_6.getType() == user.getLastGame()) {
            return null;
        } else if (GameTypeEnums.GT_7.getType() == user.getLastGame()) {
            return null;
        } else if (GameTypeEnums.GT_9.getType() == user.getLastGame()) {
            return null;
        } else if (GameTypeEnums.GT_11.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.bn_king.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_20.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.likuiFishUserList.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_37.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.goldenFishUserList.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_42.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.goldSharkUserList.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_52.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.bcbmUserList.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_92.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.tgUserList.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        } else if (GameTypeEnums.GT_103.getType() == user.getLastGame()) {
            for (Map.Entry<Integer, List<User>> entry : GameParameterAssist.lhdUserList.entrySet()) {
                for (User u : entry.getValue()) {
                    if (user.getId() == u.getId()) {
                        return entry.getKey();
                    }
                }
            }
        }
        return null;
    }

    public long getAllUserGold(int promoterId, String searchWord, IoSession session) {
        if ((searchWord == null) || ("".equals(searchWord.trim()))) {
            return this.userServiceDao.getSumGameGoldByPromoterId(promoterId);
        }
        return this.userServiceDao.SumGameGoldByPromoterId(promoterId, searchWord);
    }

    public Map<String, Object> getUserInfo(int promoterId, int userId, IoSession session) {
        User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
        Map result;
        if (user == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            result = resultFormat(true, "");
            Map um = new HashMap();
            um.put("nickname", user.getNickname());
            um.put("gameGold", Integer.valueOf(user.getGameGold()));
            um.put("payMoney", Integer.valueOf(user.getPayMoney()));
            um.put("expiryNum", Integer.valueOf(user.getExpiryNum()));
            String status = MyUtil.getSessionAttribute(session, "normal");
            if (user.getStatus() == 1) {
                status = MyUtil.getSessionAttribute(session, "disabled");
            } else if (user.getOverflow() == 1) {
                status = MyUtil.getSessionAttribute(session, "outOfRange");
            } else if (user.getShutupStatus() != 0) {
                status = MyUtil.getSessionAttribute(session, "gag");
            } else if (user.getStatus() == 2) {
                status = MyUtil.getSessionAttribute(session, "LoginFrequently");
            } else if (user.getStatus() == 3) {
                status = MyUtil.getSessionAttribute(session, "RepeatLogin");
            }
            um.put("status", status);
            String strWarningStatus = MyUtil.getSessionAttribute(session, "normal");
            if (user.getWarningStatus() == -1) {
                strWarningStatus = MyUtil.getSessionAttribute(session, "abnormal23");
            } else if (user.getWarningStatus() > 0) {
                strWarningStatus = MyUtil.format(MyUtil.getSessionAttribute(session, "abnormal1"), new Object[]{Integer.valueOf(user.getWarningStatus())});
            }
            um.put("warningStatus", strWarningStatus);
            String borrow = MyUtil.getSessionAttribute(session, "notRented");
            int count = this.computerOrderServiceDao.q_CreateSqlInt("select count(*) from ComputerOrder where user.id=? and status=0", new Object[]{Integer.valueOf(user.getId())});
            if (count > 0) {
                borrow = MyUtil.getSessionAttribute(session, "rented");
            }
            um.put("borrow", borrow);
            um.put("phone", user.getPhone());
            um.put("loginDate", (user.getLoginDate() == null) || ("".equals(user.getLoginDate())) ? MyUtil.getSessionAttribute(session, "neverLogined") : user.getLoginDate());
            result.putAll(um);
        }
        return result;
    }

    public Map<String, Object> disablePromoterAccount(int promoterId, int childPromoterId, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (childPromoter.getParentId() != promoterId) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (this.promoterServiceDao.updateStateById_1(childPromoterId)) {
                if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                    notifyAllOperatingDisableNotice((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)));
                    com.miracle9.game.util.GameParameterAssist.bx.remove(Integer.valueOf(childPromoterId));
                }
                String content = "对直属推广员" + childPromoter.getUsername() + "进行了\"禁用\"操作";
                String contentEn = "Frozen the direct extension which ID is " + childPromoter.getUsername();
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                result = resultFormat(true, "");
            } else {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "setError"));
            }
        }
        return result;
    }

    public Map<String, Object> enablePromoterAccount(int promoterId, int childPromoterId, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (childPromoter.getParentId() != promoterId) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (this.promoterServiceDao.updateStateById_0(childPromoterId)) {
                String content = "对直属推广员" + childPromoter.getUsername() + "进行了\"解禁\"操作";
                String contentEn = "Thaw the direct extension which ID is " + childPromoter.getUsername();
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                result = resultFormat(true, "");
            } else {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "setError"));
            }
        }
        return result;
    }

    public Map<String, Object> updatePromoterRemark(int promoterId, int childPromoterId, String remark, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (childPromoter.getParentId() != promoterId) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (this.promoterServiceDao.updateRemarkById(childPromoterId, remark)) {
                String content = "对直属推广员" + childPromoter.getUsername() + "进行了\"备注修改\"操作";
                String contentEn = "Change the remarks of direct extension " + childPromoter.getUsername();
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                result = resultFormat(true, "");
            } else {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "setError"));
            }
        }
        return result;
    }

    public Map<String, Object> resetChildPromoterPwd(int promoterId, int childPromoterId, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (childPromoter.getParentId() != promoterId) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (this.promoterServiceDao.updatePasswordById(childPromoterId, MyUtil.strPwdMd5Hex("888888"))) {
                String content = "对直属推广员 " + childPromoter.getUsername() + "进行了\"密码重置\"操作";
                String contentEn = "Reset the password of direct extension " + childPromoter.getUsername();
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                result = resultFormat(true, "");
                if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                    notifyAllOperatingPwdResetNotice((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)));
                }
            } else {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "setError"));
            }
        }
        return result;
    }

    public Map<String, Object> payForChildPromoter(int promoterId, int childPromoterId, int money, String pwd, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd))) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
        } else {
            Promoter childPromoter =
                    (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter.getState() != 0) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "extensionAccountDisabled"));
                return result;
            }
            int gold = MyUtil.moneyExchange(money, promoter.getChildrenPayScale());
            if (promoter.getGold() < gold) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
            } else if ((childPromoter != null) ||
                    (childPromoter.getPayMoney() > 0)) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "doNotRepeatApply"));
            } else {
                this.promoterServiceDao.updateGoldById(promoterId, gold);
                this.promoterServiceDao.addGold(childPromoterId, gold);
                result = resultFormat(true, MyUtil.format(MyUtil.getSessionAttribute(session, "payForPromoter"), new Object[]{childPromoter.getUsername(), Integer.valueOf(money), Integer.valueOf(gold)}));
                this.payLogServiceDao.saveReturnByType_0UserType_1(childPromoterId, childPromoter.getUsername(), gold, money, promoter.getUsername(), 0, "", promoterId, promoter.getGold() + promoter.getExpiryNum());
                String content = "对直属推广员" + childPromoter.getUsername() + "进行了充值操作，金额为" + money + "元";
                String contentEn = "Recharge " + money + " yuan for the direct extension which ID is " + childPromoter.getUsername();
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                    notifyAllOperating1((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)), MyUtil.format(MyUtil.getSessionAttribute(session, "promoterPayActive"), new Object[]{Integer.valueOf(gold)}));
                }
            }
        }
        return result;
    }

    public Map<String, Object> getPayForPromoterInfo(int promoterId, int childPromoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                if (childPromoter.getParentId() != promoterId) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
                } else {
                    result = resultFormat(true, "");
                    PayApply payApply = this.payApplyServiceDao.getPayApplyByUserId(childPromoterId);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "promoterHasNoRechargeApplication"));
                    } else {
                        result.put("money", Integer.valueOf(payApply.getAmmount()));
                        result.put("remark", payApply.getRemark());
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> approveChildPromoterPay(int promoterId, int childPromoterId, int money, String remark, String pwd, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            return result;
        }
        if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd))) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
            return result;
        }
        Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
        if (childPromoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            return result;
        }
        if (childPromoter.getState() != 0) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "extensionAccountDisabled"));
            return result;
        }
        synchronized (PayApplyService.expiryLock) {
            PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(childPromoterId, 0);
            if (payApply == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "payTimeout"));
            } else {
                int gold = MyUtil.moneyExchange(money, promoter.getChildrenPayScale());
                if (promoter.getGold() < gold) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
                } else {
                    boolean b = this.promoterServiceDao.updateGoldById(promoterId, gold);
                    if (!b) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
                        return result;
                    }
                    this.promoterServiceDao.addGold(childPromoterId, gold);
                    payApply.setDatetime(MyUtil.c());
                    payApply.setAmmount(money);
                    if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                        payApply.setNotice(true);
                        notifyAllOperatingSyncPayResult((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)), MyUtil.format(MyUtil.getSessionAttribute(session, "promoterPayApprovedTip"), new Object[]{MyUtil.c(), Integer.valueOf(gold)}));
                    }
                    payApply.setState(PayApply.PayApplyState.HANDLED);
                    this.payApplyServiceDao.update(payApply);
                    this.promoterServiceDao.updatePayMoney_0ById(childPromoterId);
                    String content = "对直属推广员" + childPromoter.getUsername() + "进行了充值操作，金额为" + money + "元";
                    String contentEn = "Recharge " + money + " yuan for the direct extension which ID is " + childPromoter.getUsername();
                    this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                    this.payLogServiceDao.saveReturnByType_0UserType_1(childPromoterId, childPromoter.getUsername(), gold, money, promoter.getUsername(), 1, payApply.getRemark(), promoterId, childPromoter.getGold() + childPromoter.getExpiryNum());
                    promoterAppPayCount(session, promoterId);
                    result = resultFormat(true, MyUtil.format(MyUtil.getSessionAttribute(session, "payForPromoter"), new Object[]{childPromoter.getUsername(), Integer.valueOf(money), Integer.valueOf(gold)}));
                    List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                    for (PayApply ul : logs) {
                        if (ul.getId() == payApply.getId()) {
                            logs.remove(ul);
                            break;
                        }
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> denyChildPromoterPayApply(int promoterId, int childPromoterId, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                synchronized (PayApplyService.expiryLock) {
                    PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(childPromoterId, 0);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "payTimeout"));
                    } else {
                        if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                            notifyAllOperatingSyncPayResult(
                                    (IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)), MyUtil.getSessionAttribute(session, "promoterPayDeniedTip"));
                            payApply.setNotice(true);
                        }
                        this.promoterServiceDao.updatePayMoney_0ById(childPromoterId);
                        payApply.setState(PayApply.PayApplyState.WAIVE);
                        this.payApplyServiceDao.update(payApply);
                        promoterAppPayCount(session, promoterId);
                        result = resultFormat(true, "");
                        List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                        for (PayApply ul : logs) {
                            if (ul.getId() == payApply.getId()) {
                                logs.remove(ul);
                                break;
                            }
                        }
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> expiryForChildPromoter(int promoterId, int childPromoterId, int gold, String pwd, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd))) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
            } else {
                Promoter childPromoter =
                        (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
                if (childPromoter == null) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
                } else {
                    if (childPromoter.getState() != 0) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "extensionAccountDisabled"));
                        return result;
                    }
                    if (childPromoter.getGold() < gold) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
                    } else {
                        if (childPromoter.getExpiryNum() > 0) {
                            result = resultFormat(false, MyUtil.getSessionAttribute(session, "doNotRepeatApply"));
                        } else {
                            Map promoterTime = new HashMap();
                            promoterTime.put(Integer.valueOf(childPromoterId), Long.valueOf(System.currentTimeMillis() + 120000L));
                            com.miracle9.game.util.GameParameterAssist.bz.put(session, promoterTime);
                            if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(childPromoterId))) {
                                notifyAllOperatingGold((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(childPromoterId)), gold);
                            }
                            com.miracle9.game.util.GameParameterAssist.bB.put(Integer.valueOf(childPromoterId), Integer.valueOf(gold));
                            result = resultFormat(true, "");
                        }
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> cancelWaitingExpiryPromoter(int promoterId, int childPromoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                if (childPromoter.getParentId() != promoterId) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
                } else {
                    result = resultFormat(true, "");
                    Iterator localIterator = com.miracle9.game.util.GameParameterAssist.bz.entrySet().iterator();
                    while (localIterator.hasNext()) {
                        Map.Entry entry = (Map.Entry) localIterator.next();
                        if (((Map) entry.getValue()).containsKey(Integer.valueOf(childPromoterId))) {
                            ((Map) entry.getValue()).remove(Integer.valueOf(childPromoterId));
                            com.miracle9.game.util.GameParameterAssist.bz.remove(entry.getKey());
                            break;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.bB.remove(Integer.valueOf(childPromoterId));
                }
            }
        }
        return result;
    }

    public Map<String, Object> cancelWaitingExpiryUser(int promoterId, int userId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            result = resultFormat(true, "");
            Iterator localIterator = com.miracle9.game.util.GameParameterAssist.bw.entrySet().iterator();
            while (localIterator.hasNext()) {
                Map.Entry entry = (Map.Entry) localIterator.next();
                if (((Map) entry.getValue()).containsKey(Integer.valueOf(userId))) {
                    ((Map) entry.getValue()).remove(Integer.valueOf(userId));
                    com.miracle9.game.util.GameParameterAssist.bz.remove(entry.getKey());
                    com.miracle9.game.util.GameParameterAssist.aI.remove(Integer.valueOf(userId));
                    break;
                }
            }
            com.miracle9.game.util.GameParameterAssist.bC.remove(Integer.valueOf(userId));
            IoSession s = (IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(userId));
            if (s != null) {
                MessageSend.q.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(s, "cancelWaitingExpiryUser", new Object[0]));
            }
        }
        return result;
    }

    public Map<String, Object> disableUserAccount(int promoterId, int userId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                this.userServiceDao.updateStatus(userId, 1);
                result = resultFormat(true, "");
                UserService.quitToLogin(userId, 2);
                String content = "对会员" + user.getUsername() + "进行了\"封号\"操作";
                String contentEn = "Frozen the member which ID is " + user.getUsername();
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
            }
        }
        return result;
    }

    public Map<String, Object> enableUserAccount(int promoterId, int userId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                this.userServiceDao.updateStatus(userId, 0);
                result = resultFormat(true, MyUtil.getSessionAttribute(session, "finishfrozen"));
                UserWarning userWarning = (UserWarning) this.userWarningServiceDao.q_CreateSqlFilter("from UserWarning where userId=? ", new Object[]{Integer.valueOf(userId)});
                UserWarningBak userWarningBak = new UserWarningBak();
                userWarningBak.setUserId(userWarning.getUserId());
                userWarningBak.setYaGold(userWarning.getYaGold());
                userWarningBak.setDeGold(userWarning.getDeGold());
                userWarningBak.setGiveGold(userWarning.getGiveGold());
                userWarningBak.setDeductGold(userWarning.getDeductGold());
                userWarningBak.setPayCount(userWarning.getPayCount());
                userWarningBak.setExpiryCount(userWarning.getExpiryCount());
                userWarningBak.setGameGold(userWarning.getGameGold());
                userWarningBak.setDate(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
                this.userWarningBakServiceDao.updateBak(userWarningBak);
                com.miracle9.game.util.GameParameterAssist.aJ.remove(Integer.valueOf(userId));
                String content = "对会员" + user.getUsername() + "进行了\"解封\"操作";
                String contentEn = "Thaw the member which ID is " + user.getUsername();
                this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
            }
        }
        return result;
    }

    public Map<String, Object> resetUserPwd(int promoterId, int userId, IoSession ioSession) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            return result;
        }
        User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
        if (user == null) {
            return result;
        }
        if (user.getPromoterId() != promoterId) {
            return result;
        }
        this.userServiceDao.updatePasswordById(Integer.valueOf(userId), DigestUtils.md5Hex("666666"));
        UserService.quitToLogin(userId, 5);
        result.put("card", user.getCard());
        result.put("phone", user.getPhone());
        result.put("question", user.getQuestion());
        result.put("answer", user.getAnswer());
        return result;
    }

    public Map<String, Object> getUserProfile(int promoterId, int userId, IoSession ioSession) {
        Map result = new HashMap();
        User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
        if (user != null) {
            result.put("card", user.getCard());
            result.put("phone", user.getPhone());
            if (resultInt(ioSession) == 0) {
                result.put("question", com.miracle9.game.util.GameParameterAssist.bM.get(user.getQuestion()));
            } else {
                result.put("question", com.miracle9.game.util.GameParameterAssist.bL.get(user.getQuestion()));
            }
            result.put("answer", user.getAnswer());
        }
        return result;
    }

    public Map<String, Object> updateUserProfile(int promoterId, int userId, String card, String phone, String question, String answer, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                this.userServiceDao.updateQuestionInfoById(userId, question, answer, phone, card);
                String timeStamp = MyUtil.c();
                String content = "对会员" + user.getUsername() + "进行了\"资料修改\"操作，修改手机号为\"" + phone + "\"";
                String contentEn = "The phone number of the member " + user.getUsername() + " has been changed to " + phone;
                this.promoterLogServiceDao.save_4(promoterId, timeStamp, content, contentEn);
                content = "对会员" + user.getUsername() + "进行了\"资料修改\"操作，修改安全问题为\"" + question + "\"";
                contentEn = "The security question of the member " + user.getUsername() + " has been changed to " + question;
                this.promoterLogServiceDao.save_4(promoterId, timeStamp, content, contentEn);
                content = "对会员" + user.getUsername() + "进行了\"资料修改\"操作，修改问题答案为\"" + answer + "\"";
                contentEn = "The security answer of the member " + user.getUsername() + " has been changed to " + answer;
                this.promoterLogServiceDao.save_4(promoterId, timeStamp, content, contentEn);
                result = resultFormat(true, MyUtil.getSessionAttribute(session, "updateSuccess"));
            }
        }
        return result;
    }

    public Map<String, Object> payForChildUser(int promoterId, int userId, int money, String pwd, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd))) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
        } else {
            SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
            int gold = MyUtil.moneyExchange(money, config.getPayScale());
            if (promoter.getGold() < gold) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
            } else {
                User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
                if (user == null) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
                } else {
                    if (user.getStatus() != 0) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "memberAccountDisabled"));
                        return result;
                    }
                    if (user.getPayMoney() > 0) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "doNotRepeatApply"));
                    } else if (user.getOverflow() == 1) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "userMoneyOverrun"));
                    } else {
                        this.promoterServiceDao.updateGoldById(promoterId, gold);
                        this.userServiceDao.updateGameGoldById(userId, gold);
                        this.userWarningServiceDao.updatePayCountByUid(userId, gold);
                        String content = "对会员" + user.getUsername() + "进行了\"充值\"操作，金额为" + money + "元";
                        String contentEn = "Recharge " + money + " yuan for the member which ID is " + user.getUsername();
                        this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                        this.payLogServiceDao.saveReturnByType_0UserType_0(userId, user.getUsername(), gold, money, promoter.getUsername(), 0, "", promoterId, user.getGameGold() + user.getExpiryNum());
                        user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
                        UserService.pubGoldNotice(user);
                        double totalMoney = MyUtil.goldExchange(user.getGameGold(), config.getPayScale());
                        if ((totalMoney >= promoter.getChildrenUserOver()) && (promoter.getChildrenUserOver() != -1)) {
                            this.userServiceDao.updateOverflow(userId, 1);
                            UserService.pubOverflowNotice(userId);
                        }
                        result = resultFormat(true, MyUtil.format(MyUtil.getSessionAttribute(session, "payForUser"), new Object[]{user.getUsername(), Integer.valueOf(money), Integer.valueOf(gold)}));
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> getChildUserPayApply(int promoterId, int userId, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(userId, 0);
                if (payApply == null) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "memberHasNoRechargeApplication"));
                } else {
                    result = resultFormat(true, "");
                    result.put("money", Integer.valueOf(payApply.getAmmount()));
                    result.put("remark", payApply.getRemark());
                }
            }
        }
        return result;
    }

    public Map<String, Object> approveChildUserPayApply(int promoterId, int userId, int money, String remark, String pwd, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd))) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                if (user.getStatus() != 0) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "memberAccountDisabled"));
                    return result;
                }
                synchronized (PayApplyService.expiryLock) {
                    PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(userId, 0);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "payTimeout"));
                    } else {
                        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
                        int gold = MyUtil.moneyExchange(money, config.getPayScale());
                        if (promoter.getGold() < gold) {
                            result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
                        } else {
                            boolean b = this.promoterServiceDao.updateGoldById(promoterId, gold);
                            if (!b) {
                                result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
                                return result;
                            }
                            payApply.setAmmount(gold);
                            payApply.setDatetime(MyUtil.c());
                            this.userServiceDao.updateGameGoldById(userId, gold);
                            this.userWarningServiceDao.updatePayCountByUid(userId, gold);
                            if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(userId))) {
                                payApply.setNotice(true);
                                UserService.chargeNotice(com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(userId)), payApply);
                            }
                            payApply.setState(PayApply.PayApplyState.HANDLED);
                            this.payApplyServiceDao.update(payApply);
                            this.userServiceDao.updatePayMoney(userId, 0);
                            String content = "对会员" + user.getUsername() + "进行了\"充值\"操作，金额为" + money + "元";
                            String contentEn = "Recharge " + money + " yuan for the member which ID is " + user.getUsername();
                            this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                            this.payLogServiceDao.saveReturnByType_0UserType_0(userId, user.getUsername(), gold, money, promoter.getUsername(), 1, payApply.getRemark(), promoterId, user.getGameGold() + user.getExpiryNum());
                            promoterAppUserPayCount(session, promoterId);
                            result = resultFormat(true, MyUtil.sessionAttributeFormat(session, "payForUser", new Object[]{user.getUsername(), Integer.valueOf(money), Integer.valueOf(gold)}));
                            List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                            for (PayApply ul : logs) {
                                if (ul.getId() == payApply.getId()) {
                                    logs.remove(ul);
                                    break;
                                }
                            }
                            user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
                            UserService.pubGoldNotice(user);
                        }
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> denyChildUserPayApply(int promoterId, int userId, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                synchronized (PayApplyService.expiryLock) {
                    PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(userId, 0);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "payTimeout"));
                    } else {
                        boolean notice = false;
                        if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(userId))) {
                            notice = true;
                            UserService.recharge((IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(userId)));
                        }
                        this.payApplyServiceDao.updateStateAndNotice(payApply.getId(), PayApply.PayApplyState.WAIVE, notice);
                        this.userServiceDao.updatePayMoney(userId, 0);
                        promoterAppUserPayCount(session, promoterId);
                        result = resultFormat(true, "");
                        List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                        for (PayApply ul : logs) {
                            if (ul.getId() == payApply.getId()) {
                                logs.remove(ul);
                                break;
                            }
                        }
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> expiryForChildUser(int promoterId, int userId, int gold, String pwd, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(pwd))) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (user.getGameGold() < gold) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
            } else {
                if (user.getStatus() != 0) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "memberAccountDisabled"));
                    return result;
                }
                if (user.getExpiryNum() > 0) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "doNotRepeatApply"));
                } else {
                    Map promoterMap = new HashMap();
                    promoterMap.put(Integer.valueOf(promoterId), Integer.valueOf(1));
                    com.miracle9.game.util.GameParameterAssist.aI.put(Integer.valueOf(userId), promoterMap);
                    com.miracle9.game.util.GameParameterAssist.bC.put(Integer.valueOf(userId), Integer.valueOf(gold));
                    result = this.adminService.useGameInputFromApp(userId, 0, gold, session);
                }
            }
        }
        return result;
    }

    public Map<String, Object> approveChildUserExpiry(int promoterId, int userId, int gold, String password, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(promoterId);
        if (promoter == null) {
            Map result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            return result;
        }
        if (!promoter.getPassword().equals(MyUtil.strPwdMd5Hex(password))) {
            Map result = resultFormat(false, MyUtil.getSessionAttribute(session, "passwordError"));
            return result;
        }
        User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
        Map result;
        if (user == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            if (user.getStatus() != 0) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "memberAccountDisabled"));
                return result;
            }
            synchronized (PayApplyService.expiryLock) {
                PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(userId, 1);
                if (payApply == null) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "expiryTimeout"));
                } else {
                    gold = payApply.getAmmount();
                    this.userServiceDao.updateExpiryNum(userId, 0);
                    this.promoterServiceDao.addGold(promoterId, gold);
                    SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
                    double money = MyUtil.goldExchange(gold, config.getPayScale());
                    int nFlag = this.userWarningServiceDao.updateExpiryCountByUid(userId, gold);
                    if (nFlag == -1) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "systemError"));
                        return result;
                    }
                    String content = "对会员" + user.getUsername() + "进行了\"兑奖\"操作，金额为" + money + "元";
                    String contentEn = "Exchange " + gold + " coins for the member which ID is " + user.getUsername();
                    this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                    this.payLogServiceDao.saveReturnByType_1UserType_0(userId, user.getUsername(), gold, money, promoter.getUsername(), 1, payApply.getRemark(), promoterId, user.getGameGold());
                    payApply.setDatetime(MyUtil.c());
                    payApply.setState(PayApply.PayApplyState.HANDLED);
                    this.payApplyServiceDao.update(payApply);
                    promoterAppUserPayCount(session, promoterId);
                    result = resultFormat(true, MyUtil.sessionAttributeFormat(session, "expiryForUser", new Object[]{user.getUsername(), Integer.valueOf(gold), Double.valueOf(money)}));
                    List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                    for (PayApply ul : logs) {
                        if (ul.getId() == payApply.getId()) {
                            logs.remove(ul);
                            break;
                        }
                    }
                    if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(userId)) {
                        UserService.chargeNotice(com.miracle9.game.util.GameParameterAssist.ba.get(userId), payApply);
                        payApply.setNotice(true);
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> denyChildUserExpiry(int promoterId, int userId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                synchronized (PayApplyService.expiryLock) {
                    PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(userId, 1);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "memberHasNoExchangeApplication"));
                    } else {
                        this.userServiceDao.updateExpiryNum(userId, 0);
                        this.userServiceDao.updateGameById(Integer.valueOf(userId), payApply.getAmmount(), 0);
                        boolean notice = false;
                        if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(userId))) {
                            UserService.excharge(GameParameterAssist.ba.get(Integer.valueOf(userId)));
                            notice = true;
                        }
                        this.payApplyServiceDao.updateStateAndNotice(payApply.getId(), PayApply.PayApplyState.WAIVE, notice);
                        promoterAppUserPayCount(session, promoterId);
                        result = resultFormat(true, "");
                        List<PayApply> logs = this.payApplyServiceDao.getAllPayApply();
                        for (PayApply ul : logs) {
                            if (ul.getId() == payApply.getId()) {
                                logs.remove(ul);
                                break;
                            }
                        }
                        user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
                        UserService.pubGoldNotice(user);
                        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
                        double userMoney = MyUtil.goldExchange(user.getGameGold(), config.getPayScale());
                        if ((promoter.getChildrenUserOver() != -1) && (userMoney >= promoter.getChildrenUserOver()) && (user.getOverflow() == 0)) {
                            this.userServiceDao.updateOverflow(userId, 1);
                            UserService.pubOverflowNotice(userId);
                        }
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> getExpiryForChildInfo(int promoterId, int userId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                if (user.getPromoterId() != promoterId) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
                } else {
                    PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(userId, 1);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "memberHasNoExchangeApplication"));
                    } else {
                        result = resultFormat(true, "");
                        result.put("gold", Integer.valueOf(payApply.getAmmount()));
                        result.put("remark", payApply.getRemark());
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> getExpiryForPromoterInfo(int promoterId, int childPromoterId, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            Promoter childPromoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(childPromoterId));
            if (childPromoter == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                if (childPromoter.getParentId() != promoterId) {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
                } else {
                    PayApply payApply = this.payApplyServiceDao.getByuserIdAndUserType_0(childPromoterId, 1);
                    if (payApply == null) {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "promoterHasNoExchangeApplication"));
                    } else {
                        result = resultFormat(true, "");
                        result.put("gold", Integer.valueOf(payApply.getAmmount()));
                        result.put("remark", payApply.getRemark());
                    }
                }
            }
        }
        return result;
    }

    public Map<String, Object> padBorrow(int promoterId, int userId, int deposit, String remark, IoSession session) {
        Map result = new HashMap();
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else if (this.computerOrderServiceDao.getQuantityByUidAndStatus_0(userId) > 0) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "existZhujie"));
            } else {
                ComputerOrder co = new ComputerOrder();
                co.setUser(user);
                co.setBorrowDate(MyUtil.c());
                co.setDeposit(deposit);
                co.setAdmin(promoter.getUsername());
                co.setRemark(remark);
                co.setStatus(0);
                int cnt = ((Integer) this.computerOrderServiceDao.saveReturn(co)).intValue();
                if (cnt > 0) {
                    result = resultFormat(true, MyUtil.getSessionAttribute(session, "rentSuccessful"));
                    String content = "对会员" + user.getUsername() + "进行了\"平板租借\"操作，押金为" + deposit + "元";
                    String contentEn = "Renting Pad for the direct member " + user.getUsername() + ",collected " + deposit + " yuan";
                    this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                } else {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "rentFail"));
                }
            }
        }
        return result;
    }

    public Map<String, Object> padReturn(int promoterId, int userId, int returnDeposit, String remark, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result;
        if (promoter == null) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else {
            User user = (User) this.userServiceDao.getById(Integer.valueOf(userId));
            if (user == null) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
            } else {
                if (this.computerOrderServiceDao.getQuantityByUidAndStatus_0(userId) > 0) {
                    if (this.computerOrderServiceDao.updateReturnInfoByIdAndstatus_0(userId, returnDeposit, promoter.getUsername(), remark)) {
                        result = resultFormat(true, MyUtil.getSessionAttribute(session, "returnSuccessful"));
                        String content = "对会员" + user.getUsername() + "进行了\"平板归还\"操作,归还押金" + returnDeposit + "元";
                        String contentEn = "Return Pad for the direct member " + user.getUsername() + ",returned " + returnDeposit + " yuan";
                        this.promoterLogServiceDao.save_3(promoter.getId(), content, contentEn);
                    } else {
                        result = resultFormat(false, MyUtil.getSessionAttribute(session, "returnFail"));
                    }
                } else {
                    result = resultFormat(false, MyUtil.getSessionAttribute(session, "notZhujie"));
                }
            }
        }
        return result;
    }

    public Pager queryUserPayLog(int userId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,money desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("money desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where userId=? and type=0 and userType=0 and datetime like ?", pager, new Object[]{Integer.valueOf(userId), date + "%"});
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public double getUserPaySum(int userId, String date, IoSession ioSession) {
        return this.payLogServiceDao.getSumMoneyByUidAndDate_0(userId, date);
    }

    public Pager queryUserExpiryLog(int userId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,money desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("money desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o + " " + pager.getOrder());
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where userId=? and userType=0 and type=1 and datetime like ?", pager, new Object[]{Integer.valueOf(userId), date + "%"});
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public double getUserExpirySum(int userId, String date, IoSession ioSession) {
        return this.payLogServiceDao.getSumMoneyByUidAndDate_1(userId, date);
    }

    public Pager queryBorrowLog(int userId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("borrowDate asc,status desc");
        } else {
            List orderby = new ArrayList();
            orderby.add("borrowDate asc");
            orderby.add("status desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (Iterator localIterator = orderby.iterator(); localIterator.hasNext(); ) {
                String o = (String) localIterator.next();
                sb.append("," + o + " " + pager.getOrder());
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.computerOrderServiceDao.q_CreateSqlsPager("from ComputerOrder where user.id=? and borrowDate like ?", pager, new Object[]{Integer.valueOf(userId), date + "%"});
        List list = new ArrayList();
        for (int i = 0; i < pager.getList().length; i++) {
            Object o = pager.getList()[i];
            Map map = new HashMap();
            ComputerOrder co = (ComputerOrder) o;
            map.put("id", Integer.valueOf(co.getId()));
            map.put("borrowDate", co.getBorrowDate());
            map.put("status", co.getStatus() == 0 ? MyUtil.getProperties(Integer.valueOf(resultInt(session)), "notReturn") : MyUtil.getProperties(Integer.valueOf(resultInt(session)), "alreadyReturn"));
            list.add(map);
        }
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        pager.setList(list.toArray());
        return pager;
    }

    public Map<String, Object> getUserBorrowInfo(int id, IoSession session) {
        ComputerOrder co = (ComputerOrder) this.computerOrderServiceDao.getById(Integer.valueOf(id));
        if (co == null) {
            return new HashMap();
        }
        Map result = new HashMap();
        result.put("borrowDate", co.getBorrowDate());
        result.put("repayDate", (co.getRepayDate() == null) || ("".equals(co.getRepayDate())) ? "--" : co.getRepayDate());
        result.put("status", co.getStatus() == 0 ? MyUtil.getSessionAttribute(session, "notReturn") : MyUtil.getSessionAttribute(session, "alreadyReturn"));
        result.put("deposit", Integer.valueOf(co.getDeposit()));
        result.put("returnDeposit", (co.getRepayDate() == null) ||
                ("".equals(co.getRepayDate())) ? "--" : Integer.valueOf(co.getReturnDeposit()));
        result.put("remark", co.getRemark() == null ? "" : co.getRemark());
        result.put("repayRemark", (co.getRepayDate() == null) ||
                ("".equals(co.getRepayDate())) ? "--" : co.getRepayRemark() == null ? "" : co.getRepayRemark());
        return result;
    }

    public Map<String, Object> getBorrowLogById(int id, IoSession session) {
        ComputerOrder co = (ComputerOrder) this.computerOrderServiceDao.getById(Integer.valueOf(id));
        if (co == null) {
            co = new ComputerOrder();
        }
        Map r = new HashMap();
        r.put("borrowDate", co.getBorrowDate());
        r.put("repayDate", co.getRepayDate());
        r.put("status", Integer.valueOf(co.getStatus()));
        r.put("deposit", Integer.valueOf(co.getDeposit()));
        r.put("returnDeposit", Integer.valueOf(co.getReturnDeposit()));
        r.put("remark", co.getRemark());
        r.put("repayRemark", co.getRemark());
        return r;
    }

    public Pager getDailyPayReport(int promoterId, String date, int userType, Pager pager, IoSession ioSession) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,money desc, username asc, gold desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("money desc");
            orderby.add("username asc");
            orderby.add("gold desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        if ((userType == 0) || (userType == 1)) {
            pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where parentPromoterId=? and userType=? and type=0 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), Integer.valueOf(userType), date + "%"});
        } else {
            pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where parentPromoterId=? and type=0 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), date + "%"});
        }
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public double getDailyPaySum(int promoterId, String date, int userType, IoSession session) {
        return this.payLogServiceDao.getSumMoneyBy(promoterId, date, userType);
    }

    public Pager getDailyExpiryReport(int promoterId, String date, int userType, Pager pager, IoSession ioSession) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,gold desc, username asc, money desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("gold desc");
            orderby.add("username asc");
            orderby.add("money desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o + " " + pager.getOrder());
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        if ((userType == 0) || (userType == 1)) {
            pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where parentPromoterId=? and userType=? and type=1 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), Integer.valueOf(userType), date + "%"});
        } else {
            pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where parentPromoterId=? and type=1 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), date + "%"});
        }
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public double getDailyExpirySum(int promoterId, String date, int userType, IoSession session) {
        return this.payLogServiceDao.getSumMoneyByUidAndDateType(promoterId, date, userType);
    }

    public Pager getDailyBorrowReport(int promoterId, String date, Pager pager, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            return pager;
        }
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,type desc, money desc,userName asc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("type desc");
            orderby.add("money desc");
            orderby.add("userName asc");
            orderby.remove(pager.getOrderBy() + " desc");
            orderby.remove(pager.getOrderBy() + " asc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString().replaceAll("datetime", "`datetime`"));
            pager.setOrder(null);
        }
        String padBorrow = MyUtil.getSessionAttribute(session, "userZhujie");
        String padReturn = MyUtil.getSessionAttribute(session, "userGuihai");
        String sql = "select datetime,userName,type,money from (select co.borrow_date as `datetime`,user.username as userName,'" + padBorrow + "' as type,co.deposit as money from computer_order co " + "left join user on co.user_id=user.id where co.borrow_date is not null and co.admin=? and co.borrow_date like ? " + "union all " + "select co.repay_date as `datetime`,user.username as userName,'" + padReturn + "' as type,co.return_deposit as money from computer_order co " + "left join user on co.user_id=user.id where co.repay_date is not null and co.repay_admin=? and co.repay_date like ? " + ") t1 ";
        pager = this.dao.getQuantity(sql, pager, new Object[]{promoter.getUsername(), date + "%", promoter.getUsername(), date + "%"});
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        Object pagerResult = new ArrayList();
        Object[] pagerObjectArray = pager.getList();
        if (pagerObjectArray != null) {
            for (int i = 0; i < pagerObjectArray.length; i++) {
                Map pr = new HashMap();
                Object[] poa = (Object[]) pagerObjectArray[i];
                pr.put("datetime", poa[0]);
                pr.put("userName", poa[1]);
                pr.put("type", poa[2]);
                pr.put("money", poa[3]);
                ((List) pagerResult).add(pr);
            }
        }
        pager.setList(((List) pagerResult).toArray());
        return pager;
    }

    public Map<String, Object> getDailyBorrowSum(int promoterId, String date, IoSession session) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        Map result = new HashMap();
        if (promoter != null) {
            double in = this.computerOrderServiceDao.getSumDepositByBorrowDate(date, promoter.getUsername());
            double out = this.computerOrderServiceDao.getSumReturnDepositByRepayDate(date, promoter.getUsername());
            result.put("allIn", Double.valueOf(in));
            result.put("allOut", Double.valueOf(out));
        } else {
            result.put("allIn", Integer.valueOf(0));
            result.put("allOut", Integer.valueOf(0));
        }
        return result;
    }

    public Pager getMonthlyAccountDetail(int promoterId, String date, Pager pager, IoSession ioSession) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            pager.setTotalCount(0);
            return pager;
        }
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("date asc,revenue desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("date asc");
            orderby.add("revenue desc");
            orderby.remove(pager.getOrderBy() + " desc");
            orderby.remove(pager.getOrderBy() + " asc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString().replaceAll("date", "`date`"));
            pager.setOrder(null);
        }
        StringBuilder sql = new StringBuilder();
        DateFormat df = new SimpleDateFormat("yyyy-MM");
        String nowDate = df.format(new Date());
        String strFormate = "";
        if (date.equals(nowDate)) {
            strFormate = "(now(),'%d')";
        } else {
            String strDate = date + "-1";
            strFormate = "(LAST_DAY(\"" + strDate + "\"" + "),'%d')";
        }
        sql.append("select `date`,sum(money) as revenue from ").append(" (select LEFT(`datetime`,10) AS `date`,sum(money) as money from pay_log ").append(" where type=0 and parent_promoter_id = ? and LEFT(`datetime`,7) = ? ").append(" group by LEFT(`datetime`,10) ").append(" union all ").append(" select LEFT(`datetime`,10) AS `date`,0-sum(money) as money from pay_log ").append(" where type=1 and parent_promoter_id = ? and LEFT(`datetime`,7) = ? ").append(" group by LEFT(`datetime`,10) ").append(" union all ").append(" select LEFT(`borrow_date`,10) AS `date`,sum(deposit) as money from computer_order ").append(" where admin = ? and LEFT(`borrow_date`,7) = ? ").append(" group by LEFT(`borrow_date`,10) ").append(" union all ").append(" select LEFT(`repay_date`,10) AS `date`,0-sum(return_deposit) as money from computer_order ").append(" where status=1 and repay_admin = ? and LEFT(`repay_date`,7) = ? ").append(" group by LEFT(`repay_date`,10) ").append(" union all ").append(" select concat(?,'-',day_number) AS `date`,0.00 as money from days where date_format " + strFormate + " >= day_number ").append(" ) t1 group by t1.`date`");
        pager = this.dao.getQuantity(sql.toString(), pager, promoterId, date, promoterId, date, promoter.getUsername(), date, promoter.getUsername(), date, date);
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        List pagerResult = new ArrayList();
        Object[] pagerObjectArray = pager.getList();
        if (pagerObjectArray != null) {
            for (int i = 0; i < pagerObjectArray.length; i++) {
                Map pr = new HashMap();
                Object[] poa = (Object[]) pagerObjectArray[i];
                pr.put("date", poa[0]);
                pr.put("revenue", poa[1]);
                pagerResult.add(pr);
            }
        }
        pager.setList(pagerResult.toArray());
        return pager;
    }

    public double getMonthlyAccountSum(int promoterId, String date, IoSession ioSession) {
        Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
        if (promoter == null) {
            return 0.0D;
        }
        return this.promoterServiceDao.nestingGetSumMoneyBypromoterId(promoterId, promoter.getUsername(), date);
    }

    public Pager getGameStatistics(int promoterId, String date, int type, int index, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("date asc,allPlay desc, allGet desc,allEarn desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("date asc");
            orderby.add("allPlay desc");
            orderby.add("allGet desc");
            orderby.add("allEarn desc");
            orderby.remove(pager.getOrderBy() + " desc");
            orderby.remove(pager.getOrderBy() + " asc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        int totalPlay = 0;
        int totalGet = 0;
        int totalEarn = 0;
        if ((type == -1) && (index == -1)) {
            Object obj = null;
            Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
            if (promoter.getParentId() == 0) {
                StringBuilder proIds = new StringBuilder();
                List<Integer> promoterIds = new ArrayList();
                promoterIds.add(Integer.valueOf(promoterId));
                this.promoterServiceDao1.getPromotersByParentId(promoterIds, promoterId);
                proIds.append("(");
                for (Integer pid : promoterIds) {
                    proIds.append(pid + ",");
                }
                proIds = new StringBuilder(proIds.substring(0, proIds.length() - 1));
                proIds.append(")");
                String sql = "select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and promoter_id in " + proIds.toString() + " group by datetime";
                pager = this.dao.getQuantity(sql, pager, new Object[]{date + "%"});
                sql = "select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and promoter_id in " + proIds.toString();
                obj = this.dao.executeSQLQuerySQL(sql, new Object[]{date + "%"}).uniqueResult();
            } else {
                String sql = "select date,sum(allPlay) as allPlay, sum(allGet) as allGet, sum(allEarn) as allEarn from (select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and promoter_id in (select id from promoter where parent_id = ?) group by datetime union all select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and promoter_id=? group by datetime) t group by date";
                pager = this.dao.getQuantity(sql, pager, new Object[]{date + "%", Integer.valueOf(promoterId), date + "%", Integer.valueOf(promoterId)});
                sql = "select sum(allPlay) as allPlay, sum(allGet) as allGet from (select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and promoter_id in (select id from promoter where parent_id = ?) union all select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and promoter_id=?) t";
                obj = this.dao.executeSQLQuerySQL(sql, new Object[]{date + "%", Integer.valueOf(promoterId), date + "%", Integer.valueOf(promoterId)}).uniqueResult();
            }
            if (obj != null) {
                Object[] totalObj = (Object[]) obj;
                if (totalObj.length == 2) {
                    totalPlay = (int) Double.parseDouble(totalObj[0] == null ? "0" : totalObj[0].toString());
                    totalGet = (int) Double.parseDouble(totalObj[1] == null ? "0" : totalObj[1].toString());
                    totalEarn = totalPlay - totalGet;
                }
            }
        } else if (type == -1) {
            Object obj = null;
            Promoter promoter = (Promoter) this.promoterServiceDao.getById(Integer.valueOf(promoterId));
            if (promoter.getParentId() == 0) {
                StringBuilder proIds = new StringBuilder();
                List<Integer> promoterIds = new ArrayList();
                promoterIds.add(Integer.valueOf(promoterId));
                this.promoterServiceDao1.getPromotersByParentId(promoterIds, promoterId);
                proIds.append("(");
                for (Integer pid : promoterIds) {
                    proIds.append(pid + ",");
                }
                proIds = new StringBuilder(proIds.substring(0, proIds.length() - 1));
                proIds.append(")");
                String sql = "select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and type = ? and promoter_id in " + proIds.toString() + " group by datetime";
                pager = this.dao.getQuantity(sql, pager, new Object[]{date + "%", Integer.valueOf(index)});
                sql = "select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and type = ? and promoter_id in " + proIds.toString();
                obj = this.dao.executeSQLQuerySQL(sql, new Object[]{date + "%", Integer.valueOf(index)}).uniqueResult();
            } else {
                String sql1 = "select date,sum(allPlay) as allPlay, sum(allGet) as allGet, sum(allEarn) as allEarn from (select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and type = ? and promoter_id in (select id from promoter where parent_id = ?) group by datetime union all select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and type = ? and promoter_id=? group by datetime) t group by date";
                pager = this.dao.getQuantity(sql1, pager, new Object[]{date + "%", Integer.valueOf(index), Integer.valueOf(promoterId), date + "%", Integer.valueOf(index), Integer.valueOf(promoterId)});
                sql1 = "select sum(allPlay) as allPlay, sum(allGet) as allGet from (select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and type = ? and promoter_id in (select id from promoter where parent_id = ?) union all select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and type = ? and promoter_id=?) t";
                obj = this.dao.executeSQLQuerySQL(sql1, new Object[]{date + "%", Integer.valueOf(index), Integer.valueOf(promoterId), date + "%", Integer.valueOf(index), Integer.valueOf(promoterId)}).uniqueResult();
            }
            if (obj != null) {
                Object[] totalObj = (Object[]) obj;
                if (totalObj.length == 2) {
                    totalPlay = (int) Double.parseDouble(totalObj[0] == null ? "0" : totalObj[0].toString());
                    totalGet = (int) Double.parseDouble(totalObj[1] == null ? "0" : totalObj[1].toString());
                    totalEarn = totalPlay - totalGet;
                }
            }
        } else if ((type == 0) && (index == -1)) {
            String sql1 = "select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and promoter_id=? group by datetime";
            pager = this.dao.getQuantity(sql1, pager, new Object[]{date + "%", Integer.valueOf(promoterId)});
            sql1 = "select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and promoter_id=?";
            Object obj = this.dao.executeSQLQuerySQL(sql1, new Object[]{date + "%", Integer.valueOf(promoterId)}).uniqueResult();
            if (obj != null) {
                Object[] totalObj = (Object[]) obj;
                if (totalObj.length == 2) {
                    totalPlay = (int) Double.parseDouble(totalObj[0] == null ? "0" : totalObj[0].toString());
                    totalGet = (int) Double.parseDouble(totalObj[1] == null ? "0" : totalObj[1].toString());
                    totalEarn = totalPlay - totalGet;
                }
            }
        } else if (type == 0) {
            String sql1 = "select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and promoter_id=? and type = ? group by datetime";
            pager = this.dao.getQuantity(sql1, pager, new Object[]{date + "%", Integer.valueOf(promoterId), Integer.valueOf(index)});
            sql1 = "select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and promoter_id=? and type = ?";
            Object obj = this.dao.executeSQLQuerySQL(sql1, new Object[]{date + "%", Integer.valueOf(promoterId), Integer.valueOf(index)}).uniqueResult();
            if (obj != null) {
                Object[] totalObj = (Object[]) obj;
                if (totalObj.length == 2) {
                    totalPlay = (int) Double.parseDouble(totalObj[0] == null ? "0" : totalObj[0].toString());
                    totalGet = (int) Double.parseDouble(totalObj[1] == null ? "0" : totalObj[1].toString());
                    totalEarn = totalPlay - totalGet;
                }
            }
        } else if ((type > 0) && (index == -1)) {
            Object obj = null;
            StringBuilder proIds = new StringBuilder();
            List<Integer> promoterIds = new ArrayList();
            promoterIds.add(Integer.valueOf(type));
            this.promoterServiceDao1.getPromotersByParentId(promoterIds, type);
            proIds.append("(");
            for (Integer pid : promoterIds) {
                proIds.append(pid + ",");
            }
            proIds = new StringBuilder(proIds.substring(0, proIds.length() - 1));
            proIds.append(")");
            String sql1 = "select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and promoter_id in " + proIds.toString() + " group by datetime";
            pager = this.dao.getQuantity(sql1, pager, new Object[]{date + "%"});
            sql1 = "select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and promoter_id in " + proIds.toString();
            obj = this.dao.executeSQLQuerySQL(sql1, new Object[]{date + "%"}).uniqueResult();
            if (obj != null) {
                Object[] totalObj = (Object[]) obj;
                if (totalObj.length == 2) {
                    totalPlay = (int) Double.parseDouble(totalObj[0] == null ? "0" : totalObj[0].toString());
                    totalGet = (int) Double.parseDouble(totalObj[1] == null ? "0" : totalObj[1].toString());
                    totalEarn = totalPlay - totalGet;
                }
            }
        } else if (type > 0) {
            Object obj = null;
            StringBuilder proIds = new StringBuilder();
            List<Integer> promoterIds = new ArrayList();
            promoterIds.add(Integer.valueOf(type));
            this.promoterServiceDao1.getPromotersByParentId(promoterIds, type);
            proIds.append("(");
            for (Integer pid : promoterIds) {
                proIds.append(pid + ",");
            }
            proIds = new StringBuilder(proIds.substring(0, proIds.length() - 1));
            proIds.append(")");
            String sql1 = "select datetime as date, sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet, sum(sum_ya_gold-sum_de_gold) as allEarn from game_data_log where datetime like ? and promoter_id in " + proIds.toString() + " and type = ?" + " group by datetime";
            pager = this.dao.getQuantity(sql1, pager, new Object[]{date + "%", Integer.valueOf(index)});
            sql1 = "select sum(sum_ya_gold) as allPlay, sum(sum_de_gold) as allGet from game_data_log where datetime like ? and promoter_id in " + proIds.toString() + " and type = ?";
            obj = this.dao.executeSQLQuerySQL(sql1, new Object[]{date + "%", Integer.valueOf(index)}).uniqueResult();
            if (obj != null) {
                Object[] totalObj1 = (Object[]) obj;
                if (totalObj1.length == 2) {
                    totalPlay = (int) Double.parseDouble(totalObj1[0] == null ? "0" : totalObj1[0].toString());
                    totalGet = (int) Double.parseDouble(totalObj1[1] == null ? "0" : totalObj1[1].toString());
                    totalEarn = totalPlay - totalGet;
                }
            }
        }
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        Object pagerResult = new ArrayList();
        Object[] pagerObjectArray = pager.getList();
        if (pagerObjectArray != null) {
            for (int i = 0; i < pagerObjectArray.length; i++) {
                Map pr = new HashMap();
                Object[] poa = (Object[]) pagerObjectArray[i];
                int tempPay = (int) Double.parseDouble(poa[1].toString());
                int tempGet = (int) Double.parseDouble(poa[2].toString());
                int allEarn = tempPay - tempGet;
                pr.put("date", poa[0]);
                pr.put("allPlay", Integer.valueOf(tempPay));
                pr.put("allGet", Integer.valueOf(tempGet));
                pr.put("allEarn", Integer.valueOf(allEarn));
                ((List) pagerResult).add(pr);
            }
        }
        Map pr = new HashMap();
        pr.put("date", MyUtil.getSessionAttribute(session, "total"));
        pr.put("allPlay", Integer.valueOf(totalPlay));
        pr.put("allGet", Integer.valueOf(totalGet));
        pr.put("allEarn", Integer.valueOf(totalEarn));
        ((List) pagerResult).add(pr);
        pager.setList(((List) pagerResult).toArray());
        return pager;
    }

    public Object[] getAllPromoters(int promoterId, IoSession ioSession) {
        List result = new ArrayList();
        Map total = new HashMap();
        total.put("id", Integer.valueOf(-1));
        total.put("userName", MyUtil.getSessionAttribute(ioSession, "all"));
        result.add(total);
        Map user = new HashMap();
        user.put("id", Integer.valueOf(0));
        user.put("userName", MyUtil.getSessionAttribute(ioSession, "zhiShuUser"));
        result.add(user);
        List<Promoter> childPromoter = this.promoterServiceDao.getPromotersByPromoterId(promoterId);
        for (Promoter child : childPromoter) {
            Map pMap = new HashMap();
            pMap.put("id", Integer.valueOf(child.getId()));
            pMap.put("userName", child.getUsername());
            result.add(pMap);
        }
        return result.toArray();
    }

    public Pager querySystemLog(int promoterId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime desc,content asc, contentEn asc");
        } else {
            List orderby = new ArrayList();
            orderby.add("datetime desc");
            orderby.add("content asc");
            orderby.add("contentEn asc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
      /*for (String o : orderby) {
        sb.append("," + o);
      }*/
            for (int i = 0; i < orderby.size(); i++) {
                sb.append("," + orderby.get(i));
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.promoterLogServiceDao.q_CreateSqlsPager("from PromoterLog where promoterId = ? and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), date + "%"});
        List list = new ArrayList();
        for (int i = 0; i < pager.getList().length; i++) {
            Object o = pager.getList()[i];
            PromoterLog log = (PromoterLog) o;
            Map map = new HashMap();
            map.put("datetime", log.getDatetime());
            if (resultInt(session) == 0) {
                map.put("content", log.getContent());
            } else {
                map.put("content", log.getContentEn());
            }
            list.add(map);
        }
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        pager.setList(list.toArray());
        return pager;
    }

    public void afterLogin(IoSession session) {
        int promoterId = ((Integer) session.getAttribute("id")).intValue();
        List<PayApply> payApplys = this.payApplyServiceDao.q_CreateSqlList("from PayApply where notice=0 and userType=1 and state!=0 and userId=?", new Object[]{Integer.valueOf(promoterId)});
        for (PayApply p : payApplys) {
            if (p.getState() == PayApply.PayApplyState.HANDLED) {
                if (p.getType() == 0) {
                    notifyAllOperatingSyncPayResult(session, MyUtil.sessionAttributeFormat(session, "promoterPayApprovedTip", new Object[]{p.getDatetime(), Integer.valueOf(p.getAmmount())}));
                } else {
                    notifyAllOperatingSyncPayResult(session, MyUtil.sessionAttributeFormat(session, "promoterExpiryApprovedTip", new Object[]{p.getDatetime(), Integer.valueOf(p.getAmmount())}));
                }
            } else if (p.getType() == 0) {
                notifyAllOperatingSyncPayResult(session, MyUtil.getSessionAttribute(session, "promoterPayDeniedTip"));
            } else {
                notifyAllOperatingMessage(session, MyUtil.getSessionAttribute(session, "promoterExpiryDeniedTip"));
            }
            this.payApplyServiceDao.updateNotice(p.getId(), true);
        }
        promoterAppPayCount(session, promoterId);
        promoterAppUserPayCount(session, promoterId);
    }

    private static void notifyAllOperatingLogoffNotice(IoSession ioSession) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "logoffNotice", new Object[0]));
    }

    private static void notifyAllOperatingDisableNotice(IoSession ioSession) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "disableNotice", new Object[0]));
    }

    private static void notifyAllOperatingPwdResetNotice(IoSession ioSession) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "pwdResetNotice", new Object[0]));
    }

    private static void notifyAllOperatingSyncPayResult(IoSession ioSession, String message) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "syncPayResult", new Object[]{message}));
    }

    private static void notifyAllOperatingMessage(IoSession ioSession, String message) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "syncExpiryResult", new Object[]{message}));
    }

    private void notifyAllOperatingGold(IoSession ioSession, int gold) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "showExpiryPwd", new Object[]{Integer.valueOf(gold)}));
    }

    public void promoterAppPayCount(IoSession ioSession, int promoterId) {
        Map toDo = a(promoterId);
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "promoterAppPayCount", new Object[]{toDo}));
    }

    public void promoterAppUserPayCount(IoSession ioSession, int promoterId) {
        Map toDo = b(promoterId);
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "promoterAppUserPayCount", new Object[]{toDo}));
    }

    private Map<String, Integer> a(int promoterId) {
        int payCount = this.promoterServiceDao.getQuantityByparentIdAmdPaymoney(promoterId);
        int expiryCount = this.promoterServiceDao.getQuantityByparentIdAmdExpiryNum(promoterId);
        Map map = new HashMap();
        map.put("payCount", Integer.valueOf(payCount));
        map.put("expiryCount", Integer.valueOf(expiryCount));
        return map;
    }

    private Map<String, Integer> b(int promoterId) {
        int payCount = this.promoterServiceDao.getQuantityByPromoterIdAndPayMoney(promoterId);
        int expiryCount = this.promoterServiceDao.getQuantityByPromoterIdAndExpiryNum(promoterId);
        Map map = new HashMap();
        map.put("payCount", Integer.valueOf(payCount));
        map.put("expiryCount", Integer.valueOf(expiryCount));
        return map;
    }

    public Map<String, Object> checkUserWarning(int promoterId, int nUserId, int nExpiryCount, String pwd, IoSession session) {
        Map result = new HashMap();
        result = this.payLogService.checkWarning(nUserId, nExpiryCount);
        return result;
    }

    public Map<String, Object> promoterDeduct(int parentPromoterId, int childPromoterId, int minusGold, IoSession session) {
        Map result = new HashMap();
        if (minusGold < 0) {
            logger.error("less than zero userDeduct:" + minusGold);
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "systemError"));
            return result;
        }
        Promoter childPromoter = (Promoter) this.promoterServiceDao1.getById(Integer.valueOf(childPromoterId));
        Promoter parentPromoter = (Promoter) this.promoterServiceDao1.getById(Integer.valueOf(parentPromoterId));
        if ((childPromoter == null) || (parentPromoter == null)) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else if (childPromoter.getGold() < minusGold) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
        } else {
            boolean childSuccess = this.promoterServiceDao1.addGold(childPromoterId, -minusGold);
            boolean parentSuccess = this.promoterServiceDao1.addGold(parentPromoterId, minusGold);
            if ((!childSuccess) || (!parentSuccess)) {
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "systemError"));
                return result;
            }
            childPromoter = (Promoter) this.promoterServiceDao1.getById(Integer.valueOf(parentPromoterId));
            result = resultFormat(true, MyUtil.format(MyUtil.getSessionAttribute(session, "deductForChildPromoter"), new Object[0]));
            String content = "对直属推广员" + childPromoter.getUsername() + "进行了\"扣除游戏币\"操作，扣除了" + minusGold + "游戏币";
            String contentEn = "The operation of deduct coins has been operated for the member which ID is " + childPromoter.getUsername() + " ,a total of " + minusGold + " coins";
            this.promoterLogServiceDao.save_3(parentPromoterId, content, contentEn);
            this.payLogServiceDao.saveReturnByTypeUserType_1(childPromoterId, childPromoter.getUsername(), minusGold, 0.0D, childPromoter.getUsername(), 3, "", parentPromoterId, childPromoter.getGold() + childPromoter.getExpiryNum());
        }
        return result;
    }

    public Map<String, Object> userDeduct(int parentPromoterId, int childUserId, int minusGold, IoSession session) {
        Map result = new HashMap();
        if (minusGold < 0) {
            minusGold = -minusGold;
        }
        User user = (User) this.userServiceDao.getById(Integer.valueOf(childUserId));
        Promoter parentPromoter = (Promoter) this.promoterServiceDao1.getById(Integer.valueOf(parentPromoterId));
        if ((user == null) || (parentPromoter == null)) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "accountError"));
        } else if (user.getGameGold() < minusGold) {
            result = resultFormat(false, MyUtil.getSessionAttribute(session, "notGold"));
        } else {
            int count = this.userServiceDao.updateGameById(Integer.valueOf(childUserId), -minusGold, 0);
            boolean parentSuccess = this.promoterServiceDao1.addGold(parentPromoterId, minusGold);
            if ((count <= 0) || (!parentSuccess)) {
                user = (User) this.userServiceDao.getById(Integer.valueOf(childUserId));
                result = resultFormat(false, MyUtil.getSessionAttribute(session, "systemError"));
                return result;
            }
            result = resultFormat(true, MyUtil.format(MyUtil.getSessionAttribute(session, "deductForChildUser"), new Object[0]));
            user.setGameGold(user.getGameGold() - minusGold);
            UserService.pubGoldNotice(user);
            String content = "对会员" + user.getUsername() + "进行了\"扣除游戏币\"操作，扣除了" + minusGold + "游戏币";
            String contentEn = "The operation of deduct coins has been operated for the member which ID is " + user.getUsername() + " ,a total of " + minusGold + " coins";
            this.promoterLogServiceDao.save_3(parentPromoterId, content, contentEn);
            Promoter promoter = (Promoter) this.promoterServiceDao1.getById(Integer.valueOf(parentPromoterId));
            this.payLogServiceDao.saveReturnByTypeUserType_0(childUserId, user.getUsername(), minusGold, 0.0D, promoter.getUsername(), 3, "", parentPromoterId, user.getGameGold() + user.getExpiryNum());
            SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
            if ((user.getOverflow() == 1) && ((config.getMoneyOverrun() == -1) || (MyUtil.goldExchange(user.getGameGold(), config.getPayScale()) < config.getMoneyOverrun()))) {
                this.userServiceDao.updateOverflow(childUserId, 0);
                if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(childUserId))) {
                    MessageSend.q.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(childUserId)), "unOverflow", new Object[0]));
                }
            }
        }
        return result;
    }

    public Pager queryPromoterDeductLog(int promoterId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,money desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("gold desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where userId=? and type=3 and userType=1 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), date + "%"});
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public Pager queryUserDeductLog(int promoterId, String date, Pager pager, IoSession session) {
        String orgOrderBy = pager.getOrderBy();
        String orgOrder = pager.getOrder();
        if (StringUtils.isBlank(pager.getOrderBy())) {
            pager.setOrderBy("datetime asc,money desc");
        } else {
            List<String> orderby = new ArrayList();
            orderby.add("datetime asc");
            orderby.add("gold desc");
            orderby.remove(pager.getOrderBy() + " asc");
            orderby.remove(pager.getOrderBy() + " desc");
            StringBuilder sb = new StringBuilder(pager.getOrderBy() + " " + pager.getOrder());
            for (String o : orderby) {
                sb.append("," + o);
            }
            pager.setOrderBy(sb.toString());
            pager.setOrder(null);
        }
        pager = this.payLogServiceDao.q_CreateSqlsPager("from PayLog where userId=? and type=3 and userType=0 and datetime like ?", pager, new Object[]{Integer.valueOf(promoterId), date + "%"});
        pager.setOrderBy(orgOrderBy);
        pager.setOrder(orgOrder);
        return pager;
    }

    public double getPromoterDeductSum(int promoterId, String date, IoSession ioSession) {
        return this.payLogServiceDao.getSumGoldByuserType_1(promoterId, date);
    }

    public double getUserDeductSum(int userId, String date, IoSession ioSession) {
        return this.payLogServiceDao.getSumGoldByuserType_0(userId, date);
    }

    private static void notifyAllOperating1(IoSession ioSession, String message) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "syncPayActiveResult", new Object[]{message}));
    }

    private static void notifyAllOperating(IoSession ioSession, String message) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(ioSession, "syncExpiryActiveResult", new Object[]{message}));
    }

    public Map<String, Object> changeUserControl(int id, int controlType, int controlExpire, int maxGold, int fishControlValue, IoSession session) {
        return userService.changeUserControl(id, controlType, controlExpire, maxGold, fishControlValue, session);
    }

    public Map<String, Object> controlBigFish(int type, int deskId, int userId, IoSession session) {
        return deskService.controlBigFish(type, deskId, userId, session);
    }

}
